Skip to content

Instantly share code, notes, and snippets.

@trinitronx
Forked from al3xandru/gist:1156476
Last active December 16, 2015 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trinitronx/5401863 to your computer and use it in GitHub Desktop.
Save trinitronx/5401863 to your computer and use it in GitHub Desktop.
An AppleScript to provide Open iTerm Here function within Finder.app. Forked to work with iTerm2's default Hotkey Window keyboard shortcut. (So it triggers the sliding yakuake-style Hotkey Window profile first.)
on run {input, parameters}
tell application "Finder"
set sel to selection
if (count sel) > 0 then
set myTarget to item 1 of sel
else if (count window) > 0 then
set myTarget to target of window 1
else
set myTarget to path to home folder
end if
my openTerminal(myTarget)
end tell
end run
on openTerminal(location)
set location to location as alias
set the_path to POSIX path of location
repeat until the_path ends with "/"
set the_path to text 1 thru -2 of the_path
end repeat
set cmd to "cd " & quoted form of the_path & "&& clear"
tell application "System Events" to set terminalIsRunning to exists application process "iTerm"
tell application "System Events" to key code 50 using command down
tell application "iTerm"
activate
if terminalIsRunning is true then
-- set NewTerminal to (make new terminal)
tell the current terminal
launch session "Default"
set _session to current session
tell _session
write text cmd
end tell
end tell
else
tell the current terminal
tell the current session
write text cmd
end tell
end tell
end if
end tell
end openTerminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment