Is there an addon to reveal files in a file manger fom editor window?

Hello. I’m trying to find some addon that could let me locate files (images in particular) in a file manager (Finder/Windows Explorer, etc.) from an editor window. It’s supposed to work similarly to this:

  1. Open the editor window.
  2. Hover a mouse pointer over an image.
  3. Press right-click menu to show the context menu.
  4. Press the “Reveal in Finder/Windows Explorer” item in the menu.
  5. A file manager window should be opened with the selected file in it.

Is there one?

This is something that I’ve been planning to write a basic add-on for. I’ll post a link when I publish the add-on soon. Stay tuned!

3 Likes

check the context menu (the right screenshot) of my add-on OpenInExternalEditor,Rename,Duplicate for Image,Audio,Video. In the add-on settings you can control which context menu entries are shown or hidden.

I don’t know what works on MacOS because I don’t have a mac and apple is limiting what apps can do.

2 Likes

I’ve published the add-on: Reveal in File Manager - AnkiWeb

It should work on Windows and macOS. It works the same like the option in @ijgnd’s add-on, except that it has no Linux support. I’ll probably copy that part to my add-on.

5 Likes

Thanks.

Thanks. I wish It worked in the review window as well.

Will look into adding that.

Updated: Added

3 Likes

Thank you for your great work.

Would it be possible to add rename functionality as well? (Right click on image → Rename → window with current file name and extension → file is renamed on disk and in Anki).

Will consider adding that.

1 Like

@ferophila : renaming is already supported by my add-on mentioned in this thread. I hope that abdo creates many more add-ons but in this case I’m curious what you miss in my add-on.

1 Like

I did not know about it :grinning: Will give it a try, thanks.

On macOS, renaming results in errors if the file name contains @.

Anki 2.1.55 (f38c4e2f) Python 3.9.15 Qt 5.14.2 PyQt 5.14.1
Platform: macOS-12.6.1-x86_64-i386-64bit
Flags: frz=True ao=True sv=3
Add-ons, last update check: 2022-12-09 23:01:09
Möglicherweise beteiligte Erweiterungen: <U+2068>OpenInExternalEditorRenameDuplicate for ImageAudioVideo<U+2069>

Caught exception:
Traceback (most recent call last):
  File "aqt.webview", line 562, in handler
  File "aqt.editor", line 576, in <lambda>
  File "/Users/ferophila/Library/Application Support/Anki2/addons21/1560623518/edit_insert_rename_duplicate.py", line 79, in <lambda>
    editor.saveNow(lambda: func(editor, fname, type, field))
  File "/Users/ferophila/Library/Application Support/Anki2/addons21/1560623518/rename.py", line 133, in rename
    cnt = _replace_all_img_src(ep, fname, new_filename)
  File "/Users/ferophila/Library/Application Support/Anki2/addons21/1560623518/rename.py", line 64, in _replace_all_img_src
    op_chg_cnt = mw.col.backend.find_and_replace(
  File "anki._backend_generated", line 1554, in find_and_replace
  File "anki._backend", line 148, in _run_command
anki.errors.InvalidInput: <pre>regex parse error:
    (?i)(?P<first><img[^>]* src=)(?:"Bildschirmfoto\ 2022\-12\-08\ at\ 22\.54\.07@2x\.png")|(?:'Bildschirmfoto\ 2022\-12\-08\ at\ 22\.54\.07@2x\.png')(?P<second>[^>]*>)
                                                   ^^
error: unrecognized escape sequence</pre>

@ferophila : thanks for the report.

At the moment I can’t reproduce this on 2.1.55 qt6 beta 7 on intel macos 12. I can handle file names that contain “@”.

I wonder why you seem to have the html tag “pre” in the replacement. I guess something else goes wrong on your machine …

It would be really helpful if you could do two things:

  1. if possible could you share the content of the field before you tried renaming. You might have to restore a backup to a temporary profile to get the unchanged field content, for details see Backups - Anki Manual

  2. You could run anki from the commandline with a modified version of my add-on that displays debugging messages.

To run Anki from the commandline you need to find the actual binary first. On MacOS you usually have Anki in the folder “Programme”. If you right click “Anki” in it you should see an option like “show contents”. Actually behind the anki icon there’s a whole folder that the finder just hides from you. Then you have to click through until you find the right file. It should be something like Contents/MacOS/AnkiMac (or maybe it’s just Anki)

Then you can drag and drop this path into the app terminal or you can directly go into the app terminal and enter the full path. Assuming Anki is in your /Applications folder, please open Terminal.app and run /Applications/Anki.app/Contents/MacOS/AnkiMac

The point of doing is that Anki will now show many status messages in the terminal app window.

You could modify my add-on in a text editor and change the file rename.py (source) . To find this file: Click the “show files” button in the add-on dialog when my add-on is selected - also see Managing Files - Anki Manual.

change it from

def _replace_all_img_src(parent, orig_name: str, new_name: str):
    "new_name doesn't have whitespace, dollar sign, nor double quote"
    
    orig_name = re.escape(orig_name)

to

def _replace_all_img_src(parent, orig_name: str, new_name: str):
    "new_name doesn't have whitespace, dollar sign, nor double quote"
    print(f"___orig_name is: ---{orig_name}---")    
    orig_name = re.escape(orig_name)

i.e. you insert this line print(f"orig_name is: ---{orig_name}---") (it’s important that it has four leading spaces).

After restarting anki my add-on will now always show in the terminal what it considers as the original name of the file that you want to rename. Maybe the problem in my code is earlier, i.e. that my add-on has the wrong code for reading the file name.

It would be great if you could add this line to my add-on, then run anki from the terminal and then try to rename the affected file and then post in this forum the line in your terminal that starts with “___orig_name is”.

I know this is complicated. But such print debugging is very helpful. The problem is that some bugs can’t be reproduced on other machines so that help from the user is needed. Knowing this can also be useful if you want another add-on developer to take care of a problem only you have …

@ferophila : to narrow it further down: Do you have the same problem in 2.1.54? You can have both anki versions installed at the same time. On MacOS in the folder applications/Programme before I install a new Anki version I rename the old Anki to something like “Anki54qt6”. Only after this I install Anki 2.1.55 (which will have the default name Anki). This allows me to quickly test with older versions.

Sorry for hijacking this thread.

On MacOS 12 with anki 2.1.55 I couldn’t @abdo 's Reveal in File Manager nor my add-on to show path of an image in the finder. After clicking the action in the anki context menu the finder just gets focused but the folder shown in the finder is not adjusted/changed/updated.

1 Like

I need time to look into this.