Jump to content

Open current Finder window in Terminal/iTerm and vice versa


Recommended Posts

So here's a workflow to open the current Finder window in Terminal or iTerm, depending on what you like to stick with. Also the other way round is possible.

 

  • ft: open current Finder directory in Terminal
  • tf: open current Terminal directory in Finder
  • fi: open current Finder directory in iTerm
  • if: open current iTerm directory in Finder

For Path Finder fans:

 

  • pt: open current Path Finder directory in Terminal
  • tp: open current Terminal directory in Path Finder
  • pi: open current Path Finder directory in iTerm
  • ip: open current iTerm directory in Path Finder

 

GitHub.

Direct Download.

 

screenshot_ft.png

Edited by iEnno
Link to post

Very nice. I find that ft seems to match FaceTime more than this plugin, I'd consider it suitable for a hotkey to go finder->terminal.

 

Just scroll to it and execute it several times. Then Alfred will put it at the top of the list due to number of times selected. Very useful feature!

Link to post

Is there any way to make it open in a new terminal tab instead of a new window?

Will have a look into, thanks for suggestion.

 

Nice one!

Keep in mind you can also do "open ." in terminal or iTerm and open it's current path in Finder

Well, that's exactly what the script does. It's just the Alfred way ;)

 

Found this on Github, very nice and easy to use. Really like it.

Thanks, man. Always nice to hear that something I built for myself is helpful to others. Really appreciate it.

Link to post

New Tab should be fairly easy to do, if you're not afraid of (or generally opposed to) GUI scripting with AppleScript that is  :)

 

tell application "Terminal"
	activate
	tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
end tell

 

 

Should work identically for iTerm as it uses the same shortcut for new Tab.

I don't think there's another way since neither Terminal.app nor iTerm directly expose Tabs to AppleScript AFAIK.

Link to post

Handy workflow! I made a context aware equivalent triggered by a hotkey. If you're in Finder when you use it it'll open the current directory in Terminal, if you're in Terminal when you use it it'll open the current directory in Finder. I didn't bother including iTerm as I never use it. I'm sure that anyone who's using this kind of workflow will be more than capable of adding support for iTerm, should they need it :-) I'd appreciate any critiques of the AppleScript code I wrote. It's fairly messy, but anything neater (in terms of code) was less robust in actual use.

 

Download: Directory Switcher

Edited by Subject22
Link to post
  • 7 months later...
  • 3 weeks later...
  • 9 months later...

@politicus: ForKlift is a hard one, because neither does it support AppleScript nor does it work with the standard "open" command in terminal. I found this and managed to get it work by triggering the following AppleScript:

on alfred_script(q)
	tell application "iTerm"
		tell the current session of current terminal
			write text "absPath=`pwd`
 
(cat<<EOF
 
if application \"ForkLift\" is not running then
    activate application \"ForkLift\"
    delay 1
end if
 
activate application \"ForkLift\"
 
tell application \"System Events\"
    keystroke \"g\" using {command down, shift down}
    keystroke \"$absPath\"
    keystroke return
end tell
 
EOF
) | osascript"
		end tell
	end tell
end alfred_script

Try it yourself and tell me if that works for you.

Link to post

When I press Ctrl+T it writes "open -a 'Path Finder' ./" in iTerm and hit enter.  

If I knew Path Finder was also an option I would have just sugested using the keyword ip. It will open the current iTerm directory in Path Finder thanks to a user contribution on github. I will update the initial post to state this clear.

Nevertheless Keyboard Maestro seems like a good fit for this. You could also use TextExpander which I use for common terminal commands. There are many ways to achieve your goal, so I'm glaf you found yours :)

Link to post
  • 1 year later...

Hello miromann,
 
It’s not good form to hijack the thread to publicise your workflow, particularly with dubious claims. It would be one thing if someone had mentioned something they were missing from this workflow and you had one that filled the user’s need, but that does not seem to be the case at all, here.

I’ve tried your workflow, and didn’t find it any any faster (not noticeably, anyway) and it didn’t seem to work as robustly (never worked at opening in my Finder window), be as well put together (pressing ⌥ has a blank message), and it doesn’t do as much (PathFinder support, for example, or opening terminal’s current directory in Finder, as well as the reverse).

All of those are fixable, though, and would be better discussed in their own thread. You should start your own post, as that would even give better visibility to your workflow.

Link to post
  • 1 year later...

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