Jump to content

Looking for a method to show a file in Finder


Recommended Posts

Posted (edited)

I know there are lots of questions about 'Show in Finder' already, but none of them can fit my need.

 

I want to reveal a file in Finder with a hotkey when using my text editor (any apps like that). For example, in Xcode, I left click to select a .h file and press a hotkey, then Finder opens and jump to where the .h file is. In other words, the workflow is a shortcut to right click on a file and click 'Show in Finder' in the popup menu.

 

If there is any way to do that, please let me know. The most stupid solution in my brain is to mimic the manual operation using applescript. But I don't know how to select the item called 'Show in Finder' in a menu.

 

Regards,

wyudong

Edited by WangYudong
Posted

So you want to have the name of/reference to a file selected on your text editor, press a hotkey, and have it shown in Finder?
 
That’s not possible unless we know exactly which apps you want to use it with, because it’ll be app-dependent. To do that, the app will need to tell Alfred which file reference is selected, and that depends entirely on the app. If the app can do it, it will almost certainly be given with AppleScript, and the app needs to have implemented support for that.
 
If, on the other hand, all you want to do is select the “Show in Finder” option that your text editor already has, then you have two options:

  • Use AppleScript to select the option from the menu bar.
  • Add/change the keyboard shortcut for the action itself.

I recommend the second option. It’s quickest, less error prone, and you don’t even need Alfred. Open System PreferencesKeyboardShortcutsApp Shortcuts. Press the +, add your app, “Show in Finder” (or whatever the option is called, exactly), and the desired shortcut.

Posted

Thanks Vítor, your suggestion is great and works.

 

I just post what I've done and let's if anyone can improve it. I've added 'Show in Finder' hotkey for both Xcode and Atom in keyboard shortcuts in system preferences. However, I need two different ways to reveal a file.

  • For Xcode, left click a file and press the hotkey.
  • For Atom, right click a file (menu popup) and press the hotkey.

The reason caused the difference is Xcode has 'Show in Finder' in FileShow in Finder, whereas Atom hasn't. The 'Show in Finder' is located in the menu when right clicking a file.  :(

Posted

In that case, you'll have to write an AppleScript (or plugin) for Atom.

Unfortunately, as is usually the case with non-native apps, Atom's AppleScript support sucks.

The best you can do, I think, is to grab the title of the window and try to reassemble that into a filepath. This grabs the title of the front Atom window: tell application "Atom" to return name of first window

An alternative solution (and this is what I've done with Sublime Text) is to write an Atom plugin that saves the path of the currently active file somewhere (say, to ~/.current_atom_file).

Then you can grab the filepath from there to do whatever. I mostly use it for my cds shell command (change to the directory of the current Sublime file).

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...