Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An AppleScript to provide Open iTerm Here function within 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
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"
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
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