Skip to content

Instantly share code, notes, and snippets.

@ideabucket
Last active October 27, 2018 15:38
Show Gist options
  • Save ideabucket/9945498 to your computer and use it in GitHub Desktop.
Save ideabucket/9945498 to your computer and use it in GitHub Desktop.
"Go Here in iTerm2" handler for BBEdit

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

You can just run this from the Scripts menu, but if you want to have BBEdit use it for View → Go Here in Terminal:

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
@awksedperl
Copy link

Howdy ideabucket. I made some revisions to a fork of this (thanks!), which are here: https://gist.github.com/awksedperl/9ba777980a4c2a9ceb8e2221558686ca/revisions. Is there a repo for this, or should there be? Not sure what the proper conventions for gist-based stuff are. Anyway, thanks and I hope my changes prove helpful, esp. since I am not an AppleScript hacker.

@avilior
Copy link

avilior commented Oct 27, 2018

The following seems to work now with BBEDIT 12 and iTerm2 3.2.4:

defaults write com.barebones.bbedit TerminalBundleID -string "com.googlecode.iterm2"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment