Jump to content

Go To Current File (in Terminal or Finder)

Recommended Posts

Go To Current File Assign a keyboard shortcut to quickly go to the file (in Terminal, Finder, iTerm, or Alfred's File Action Window) for the file in the frontmost app.  For example, while working on a presentation in Keynote a quick keyboard shortcut can take you to the corresponding directory in Finder or Terminal.  Tested to work on most popular applications. 


(link goes to GitHub for README and downloads)
Edited by andrewning
Link to comment
  • 2 weeks later...
  • 4 weeks later...

This is really useful. I also appreciate the rewrite as splitting actions up into separate scripts has made it much easier to modify and understand. 


Most likely already implemented in one way or another but I wanted to make a quick addition to the workflow and replicate the very useful "Get and Browse document in Alfred" workflow but using the template you created. so I had everything in one workflow. It would take you 10 seconds to put this together yourself but perhaps you don't want it or just forgot about revealing in alfred's file browser. 


Hopefully someone finds it useful, only takes you to the directory and can't select the file for you like the workflow can in Finder, new feature of latest update and my favorite.

on run theType
	-- get path to frontmost document
	tell application "Finder" to set dir to POSIX path of ((container of (path to me)) as alias)
	-- if theType as string is "MS" then -- different loading script if user has MS Office
	--	set pathscript to load script dir & "pathMS.scpt"
	-- else
	set pathscript to load script dir & "path.scpt"
	-- end if
	set p to getPath() of pathscript
	-- open in finder
	tell application "Alfred 2" to search p
end run

I do not think this warrants a pull request but I am sure it can be more robust. Would you use this addition to your workflow or have you already strung a couple of scripts together for this functionality and the ability to use Alfred 2's wildcard support? Thanks again for posting this here and maintaining a repo of workflows so updates are easy to stay on top of. 

Link to comment

I hadn't thought about this. I like the suggestion and would be happy to add it, but could you clarify a bit for me what behavior you are expecting.  I'm not familiar with the "Get and Browse document in Alfred" workflow, and couldn't seem to find it from a quick search.  Do you want to pull up the exact file in Alfred's file browser, or the containing directory?  I'm assuming your goal is to right arrow over on the document to be able so you can select one of the file actions?

Link to comment

I added a capability to open the file in Alfred's File Action Window, which I think is you're after.  It's just the one line you noted, but I added a couple more lines to trigger the "right arrow" keystroke so that the file action window was opened automatically.  I also needed to introduce a slight delay before the keystroke.  The delay I chose seemed to be the right length for my computer, but may need to be longer for some.  New version pushed to GitHub.

Link to comment

Wow, I really need to make sure I am not simply reading the last post ever again. Sorry I missed the initial response so this is the third time I start over since I raise and/or answer items no longer relevant. I'll make this quick if your still around.

- Most important, thank you! I appreciate you taking the time to consider and better yet adding the feature to the workflow. I hope others find it as useful as I do.


- As you can tell... Yes, you hit the functionality I was hoping to have implemented or thought could be useful dead center.


- Everything is fast and solid but I use either function or control not the right arrow button to bring up the file action pane. I found a resource of keycodes and plugged both in there but control and fn are not receiving the same kind of love as the default ➡ key does and so I am going to play with it for a bit and see if I can get it working and most likely need to delay it a bit more.


Find keycode chart here but you can find them with lots of one trick third pony applications. I believe I remember terminal responding with key codes in the past. ..



Again, thanks for implementing the feature and taking it a step further with the action panel being invoked automatically by the applescript. That is really the end result most of us are hoping to achieve so this is great, I just need to get my setup (function(fn) and control modifiers to work. Definitely should so let me not take up more of your time unless I simply have racked my brain and still am receiving only the file path with file selected.

Link to comment

For the function key this worked for me

tell application "System Events" to key code 63

for the control key this worked

tell application "System Events"
    key down control
    key up control
end tell

However, I had to increase the delay time a little for these alternatives to work.  The reason I used the ASCII character for the right arrow is that it is universal.  Key codes can change from keyboard to keyboard.  The control one though should be universal as well.

Link to comment

Finally figured out what was going on, at least in my case but you will be able to confirm with your settings. I had multiple hotkeys for each script, I know, a bit much but so darn useful it deserves more! Anyways, with those key codes being called with system events in the same script only one hotkey was actually pulling up file action menu while the other stopped at the selected file. I thought pulling up the selected file in the file browser was the intent until I read your post over with a little attention being spared.


If you have the hotkeys configured to "Pass Through Modifier Keys (Fastest)" which is not the default but rather the third option after double clicking the hotkey cell and then control click on the actual hotkey combination. I usually always get rid of the default "Simulate modifier keys" and throw in the fastest option so it was not until I swapped their behavior until realizing that the modifiers alfred was simulating was causing the file action to never get invoked.


Default right arrow shouldn't witness these problems but perhaps you have yours set this way once you build and share the workflow as they are working with standard settings offering to simulate modifiers by the time i download the workflow.


Either way, all is well and I have a new most used hotkey, two of them! Thanks again and if you do not see any reason why having the alfredfinder,scpt hotkey to have it's default option be to skip/pass through modifiers it might save some people a headache wondering why it doesn't work or going on thinking that the file action has to be invoked manually if they do not use the right arrow as an action key.


I am glad you put this idea into the workflow, A hotkey for bringing me to the file where I can manually glob search the directory after hitting delete or invoke the file action with control or function. Two hotkeys inevitably helped me find the problem, now they will be the problem when I can't remember anything and every accidental key stroke invokes a random script tied to alfred triggers.

Link to comment

Interesting.  I didn't even know about that hidden "Trigger behavior" for the modifier keys in Alfred.  I just use the default "Simulate modifier keys released", but I tried all three options and all three triggers (right arrow, function, or control) worked fine for me for any of the trigger behaviors.  In any case, I'll leave the default as is, but your comment will be helpful for those who run into the same issue.  Also thanks again for the suggestion of adding the file action option.  I've actually started using that quite a bit lately to quickly email someone the file I'm currently working on.

Link to comment

Thanks again for doing all the heavy lifting! Definitely do not bother with the hotkey phantom bug and I say that as there could be a plethora of other reasons I ran into the problem of one hotkey working while another attached to the same script failed. If I have some time soon I will make a thorough test of the "problem" and report any notable results. I am still on 10.8.5 so maybe it is that, enough with the speculation though and I have nothing more to go on as I truly haven't attempted to reproduce the effects, or lack thereof an actions menu being called up by the key code(s). I have it working so I am happy whatever I changed, possibly the very well hidden hotkey trigger options, but I can't say for certain and to make it a bit murkier I do not know what the real differences of the options are although I am glad you learned of a new feature to take advantage of in your current and future workflows.


If I think of anything mind blowing, doubtful, I will shoot you a message. I have always been "bothered" by unsaved docs, especially temporary scratch pad type text documents I seem to accumulate. I have to really think this out as I have no idea what this feature of the workflow's end goal would be let alone accomplishing it so if I iron out anything that makes sense hopefully I can translate my intention.


Okay, Throwing it out very quickly absolutely no thought given to it other than the last few minutes, my disclaimer of sorts. Anyways, say the user has a temp textedit file open and they want to save the file with a title based on the first sentence of the file, say everything before the first punctuation mark becomes the title and it is saved in a folder under the bundle identifier of the app that "saved" it. If no front window is open/showing but the app is running feeding alfred a list of the files to choose form or action when ready m


no, no, no - absolutely nothing to do with the intent and purpose of this workflow. Let me think about it! Thanks again for all the help, Cheers!

Link to comment

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...