Last active
August 18, 2024 13:19
-
-
Save stecman/97bbe21b59613aa6c6c025ae85871438 to your computer and use it in GitHub Desktop.
New Kitty terminal window global hotkey on Mac OSX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Open a new kitty terminal window on MacOS | |
# | |
# 1. Copy this script into AppleScript Editor and save it somewhere | |
# 2. Use something like Apptivate to run the script on a global hotkey: | |
# http://www.apptivateapp.com/ | |
# | |
# Note this script doesn't work well as a Service through Automator as the | |
# "click menu" functionality requires accessibility privileges granted. | |
# Services run as the focused app, so that setup would require every context | |
# the shortcut is run from to have accessibility granted. | |
on is_running(appName) | |
tell application "System Events" to (name of processes) contains appName | |
end is_running | |
if not is_running("kitty") then | |
tell application "kitty" to activate | |
else | |
tell application "System Events" to tell process "kitty" | |
click menu item "New OS Window" of menu 1 of menu bar item "kitty" of menu bar 1 | |
end tell | |
end if |
For some reason I get this:
System Events got an error: Can’t get menu item "New OS Window" of menu 1 of menu bar item "kitty" of menu bar 1 of process "kitty". (-1728)
For line 20 (click menu item
...), this works for me:
keystroke "n" using {shift down, command down}
Thanks for saving me the pain of applescript.
To fix this script replace of menu bar item "kitty"
with of menu bar item "Shell"
.
on is_running(appName)
tell application "System Events" to (name of processes) contains appName
end is_running
if not is_running("kitty") then
tell application "kitty" to activate
else
tell application "System Events" to tell process "kitty"
click menu item "New OS Window" of menu 1 of menu bar item "Shell" of menu bar 1
end tell
end if
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your snippet! It's exactly what I was looking for, I just had to change the menu bar item name to Shell as it has changed in recent versions I guess