Open In External Editor, Rename, Duplicate for Image, Audio,Video [Official thread]

If you have a problem with the add-on add-on OpenInExternalEditor,Rename,Duplicate for Image,Audio,Video post in this thread. This way I get notified. If you make a new thread I might miss it.

Hello, I’m trying to open a card field in VSCode for Mac by setting the option to “code” or “code --wait” with no luck. The textfield flashes but nothing happens. The only way it works is if I set “open -t” in the options, but then VSCode doesn’t save back to the field.

I’m running Anki 2.1.28 and VSCode 1.47.3 on MacOS 10.14.6.

Thanks for your help!

The add-on “OpenInExternalEditor,Rename,Duplicate for Image,Audio,Video” is meant to edit image, audio, and video files in an image editor like paint or audio editor like audacity. I would never use VSCode for this.

If you want to edit the html source code in VSCode I would use External Editor, if you want to edit some latex maybe text editor for Latex, the selection or html source (FORK).

You write about “the option” but my add-on has about 20 different config options so I don’t know what you mean. If you really want to use my add-on here I need more info like the whole config and exact steps you take and how this could work with VSCode.

Sorry I’m already using External Editor, I just posted in the wrong thread!

Hello, I want to edit image on Win10 with its built-in software"Photos" ,
but I can’t find its path, so I can’t add it to add-on’s configuration.
Win10‘s built-in software seems can’t to find their path.
Could you give me some help?

@hrdom: If you google for something like “windows store app cli” you should find guides on how to find their path, see e.g. here.

But that’s not enough. The add-on passes the filename as a command line argument to the binary. But as far as I see app store apps often don’t take command line arguments. So even if you have find the path you might fail. I have no solution for this. I just use regular windows apps that I installed myself like paint .net.

Instead of my add-on maybe also have a look at Image Editor. I have never used this add-on but it seems to be independent from your local apps so that you don’t have the problem of calling an external binary.

1 Like

Thank you.
I’ll have a look and decide to use regular windows apps if it has some problem.

I’m using anki version 2.1.5 on Windows 10 and when I am trying to install your addon, it’s says that either the code is invalid, or that it’s not available for my version.
Is there a way to make it work ?

@benten: My add-on depends on features that were introduced in Anki 2.1.15. So 2.1.5 is too old. As an add-on uploader I can set compatibility info and I set on Ankiweb that only users with 2.1.15 or newer can install it. So you would need a newer Anki version to use my add-on.

Hi, i want to edit video and there is a video editing software on Windows 10, i don’t know if it’s useful.Can you please recommend the software you use or give me some advice?
Thanks in advance.

[Bug report]

The image rename doesn’t handle Cyrillic characters. (Would submit a PR on Github, but it looks like the repo has been removed…) In any case, here’s the exception:

Traceback (most recent call last):
  File "aqt/", line 526, in handler
  File "aqt/", line 534, in <lambda>
  File "/Users/alan/Library/Application Support/Anki2/addons21/1560623518/", line 79, in <lambda>
    editor.saveNow(lambda: func(editor, fname, type, field))
  File "/Users/alan/Library/Application Support/Anki2/addons21/1560623518/", line 154, in rename
    backup_changed_filenames(fname, newfilename)
  File "/Users/alan/Library/Application Support/Anki2/addons21/1560623518/", line 123, in backup_changed_filenames
UnicodeEncodeError: 'ascii' codec can't encode characters in position 52-56: ordinal not in range(128)


I believe this addresses the exception (basically, just open the logging csv file with UTF-8 encoding.)

def backup_changed_filenames(old, new):
    addon_dir_path = os.path.join(os.path.dirname(__file__))
    renamed_file = os.path.join(addon_dir_path, "user_files", "renamed_files.csv")
    with open(renamed_file, "a", encoding='utf-8') as targetfile:

Also added a newline after each log entry…

@OjisanSeiuchi : Thanks for fixing this bug. I just uploaded a new version to ankiweb. If you find other problems or have other fixes please let me know. I removed the github repo because I often forgot to push changes I made and I figured no repo is better than a dated one (at least as long as you can get my most current version from ankiweb).

@ijgnd No worries - sometimes public repos can be a headache - different coding styles, trust factor, etc. Anyway, thanks for your contributions to the Anki community - really appreciate it. Happy holidays.

There is a bug in line 106 - I’m sorry I didn’t capture the stack trace; but the fix looks straightforward. The return type of mw.col.backend.find_and_replace() is an OpChangesWithCount and to increment that change count, must access its count property, otherwise the increment assign operator fails. Here’s the entire method for _replace_all_sound_src(): Functioning correctly on macOS/Anki 2.1.48. [LATER] - I guess there’s a similar issue with the corresponding img method, too.

def _replace_all_sound_src(orig_name: str, new_name: str):
    "new_name doesn't have whitespace, dollar sign, nor double quote"
    old = f"[sound:{orig_name}"
    new = f"[sound:{new_name}"

    # Compatibility: 2.1.0+
    n = mw.col.findNotes("[sound")

    replaced_cnt = 0
    if anki_point_version >= 28:
        op_chg_cnt = mw.col.backend.find_and_replace(
        replaced_cnt += op_chg_cnt.count
        replaced_cnt += findReplace(col=mw.col, nids=n, src=old, dst=new, regex=False, fold=False)
    return replaced_cnt

@OjisanSeiuchi : Thanks for another fix. I just uploaded a new version. I made a small change so that old anki versions still work and tried to adjust it to the rename image function as you suggested.

I re-added the most recent code of this add-on to github at GitHub - ijgnd/anki21__OpenInExternalEditor_Rename_Duplicate_for_Image_Audio_Video . This should make it easier for you if you have any more improvements.