Jump to content
iEnno

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

Share this post


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.

Share this post


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!

Share this post


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.

Share this post


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.

Share this post


Link to post

For me iTerm opens a new Tab. Terminal doesn't. Maybe there is a setting to globally open new windows as new tabs. If not, sticking with franzheidl's AppleScript should be doing the job.

Share this post


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

Share this post


Link to post

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

Share this post


Link to post

It is not working.

No error. 

 

All I have is iTerm processes the script.

Forklift becomes the frontmost application. I hear a weird noise. 

 

That's all.

Share this post


Link to post

@iEnno Alright, so I've found the solution... with Keyboard Maestro.
 

I just attached a keyboard shortcut to an insert text action.

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

 

Problem solved  :)

Thanks for your help.

Share this post


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 :)

Share this post


Link to post

Keyboard Maestro is a great app but the developer doesn't know how to copy the iTerm current directory to the clipboard...

 

I wish there was an Keyboard Maestro action for it.

Share this post


Link to post

Hi!

 

Check this: https://github.com/miromannino/alfred-new-terminal-window

 

It opens a new Terminal/iTerm window in the current space. 

Holding the alt key, the new window is also opened opened in the current frontmost Finder folder.

 

It is really faster compared to others, really important for me since I use the terminal for almost everything! :)

 

Hope it helps!

Edited by miromann

Share this post


Link to post

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.

Share this post


Link to post

I know this is an old post but....

Very very nice. I like it.

Now I do not have to type long-winded paths to get to the directory I want.

Share this post


Link to post

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
×