Skip to content

Instantly share code, notes, and snippets.

@KL-7
Forked from al3xandru/gist:1156476
Created March 3, 2012 16:26
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 KL-7/1966887 to your computer and use it in GitHub Desktop.
Save KL-7/1966887 to your computer and use it in GitHub Desktop.
Open iTerm in Current Folder
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 "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