Skip to content

Instantly share code, notes, and snippets.

@bobguo
Forked from lsloan/ Open Selected Finder Folder in iTerm
Last active December 13, 2016 23:00
Show Gist options
  • Save bobguo/5f1417f0aaa63f4d979c to your computer and use it in GitHub Desktop.
Save bobguo/5f1417f0aaa63f4d979c to your computer and use it in GitHub Desktop.
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 & "&& echo $'\\ec'"
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