Skip to content

Instantly share code, notes, and snippets.

@enkeboll
Last active December 3, 2024 10:53
Show Gist options
  • Select an option

  • Save enkeboll/728f7fa1804bb00ff98d to your computer and use it in GitHub Desktop.

Select an option

Save enkeboll/728f7fa1804bb00ff98d to your computer and use it in GitHub Desktop.
Open Folder in iTerm2 from Finder
#!/usr/bin/osascript
# This is my version of
# http://peterdowns.com/posts/open-iterm-finder-service.html
# modified for iTerm 2.9+
# Create this as an "Application", save it as a .app file, and
# drag it onto the Finder window while holding the command key
# (in Yosemite, the command and option keys)
on run {input, parameters}
tell application "Finder"
set dir_path to quoted form of (POSIX path of (folder of the front window as alias))
end tell
CD_to(dir_path)
end run
on CD_to(theDir)
set wasRunning to false
if application "iTerm" is running then
set wasRunning to true
end if
tell application "iTerm"
activate
if wasRunning then
tell current window
create tab with profile "Default"
end tell
end if
set CDcommand to "cd " & theDir & "; clear;"
try
tell current session of current window
write text CDcommand
end tell
on error
create window with profile "Default"
tell current session of current window
write text CDcommand
end tell
end try
end tell
end CD_to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment