I’ve always liked GNOME’s (and probably on other Linux desktops as well) feature of launching a terminal window anywhere with a global shortcut key Ctrl+Alt+T , and have configured my MacOS to achieve the same using Apptivate since a long time ago. Somehow it stopped working last week so I looked to fix it and refine the implementation.
I originally used this script reyjrar/New-iTerm-Window.scpt with Apptivate, but it seems to break with the latest iTerm (iTerm2 3.2.0beta9) in multiple places.
New implementation
Follow the steps in “Creating System-Wide Keyboard Shortcut To Launch Applications" on StackOverflow, replace Step 4 with the following:
- Search for “AppleScript", create a “Run AppleScript" action.
-
Paste the AppleScript as follows:
on run {input, parameters}
if application "iTerm" is running then
tell application "iTerm"
create window with default profile command "/bin/bash -l"
end tell
else
activate application "iTerm"
end if
end run
Then continue to follow the steps from the Stackoverflow answer.
Now you can remove Apptivate! It’s not needed anymore.
References that have helped me throughout the process:
- https://apple.stackexchange.com/questions/286943/how-do-i-write-a-script-that-opens-an-iterm2-window-and-runs-a-command
- The old scpt used “System Events" to query running application, but I found the new method “if application “iTerm" is running then"
Bonus: Open new Finder window
Same step as above, but different script:
on run {input, parameters}
tell application "Finder"
activate
set new_window to make new Finder window to home
end tell
end run
Reference:
Github
These 2 workflows are on Github: https://github.com/pellaeon/Dotfiles/tree/master/workflow