Skip to content

Instantly share code, notes, and snippets.

@bunam
Forked from ideabucket/Go here in iTerm2.scpt
Last active August 29, 2015 14:08
Show Gist options
  • Save bunam/f74020a27946a8525008 to your computer and use it in GitHub Desktop.
Save bunam/f74020a27946a8525008 to your computer and use it in GitHub Desktop.

“Go Here in iTerm2” handler for BBEdit

This is a little helper script for BBEdit to make View > Go Here in Terminal use iTerm2 instead of Terminal.app. You can't simply give BBEdit iTerm2's bundle ID directly because iTerm2 doesn't respond to the open instruction from BBEdit, for unknown reasons.

It's based on this pastebin which in turn was based on rwilcox/open_here.applescript. It differs from both of these in that it will open a new tab in the frontmost iTerm2 window if there is one, rather than always creating a new window.

To install, open the .scpt file in AppleScript Editor. Run it to check it works, if you want. Then File > Export…, choose File Format "Application", and tick "Run-only".

You'll get an application called “Go here in iTerm2.app”. Put this somewhere suitable. /Applications/Utilities is a good choice.

Then from the command line issue this command:

defaults write com.barebones.bbedit TerminalBundleID -string "com.apple.ScriptEditor.id.Go-here-in-iTerm2"

If you changed the filename, you'll need to replace com.apple.ScriptEditor.id.Go-here-in-iTerm2 with whatever the new bundle ID is.

-- based on http://pastebin.com/MSPZWWAj
-- which was in turn based on https://gist.github.com/2006738
-- but will open a new tab in the current terminal if one is open, rather than always creating a new terminal
tell application "BBEdit" to set theFile to file of document 1
tell application "Finder" to set theFolder to (container of file theFile) as alias
set theUnixPath to POSIX path of theFolder
tell application "iTerm"
if exists current terminal then
set theTerm to current terminal
else
set theTerm to (make new terminal)
end if
tell theTerm
launch session "Default"
tell the last session
write text "pushd \"" & theUnixPath & "\" && clear"
end tell
end tell
activate
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment