Skip to content

Instantly share code, notes, and snippets.

@stecman
Last active April 19, 2024 23:00
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stecman/97bbe21b59613aa6c6c025ae85871438 to your computer and use it in GitHub Desktop.
Save stecman/97bbe21b59613aa6c6c025ae85871438 to your computer and use it in GitHub Desktop.
New Kitty terminal window global hotkey on Mac OSX
# 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
@madx
Copy link

madx commented Feb 23, 2022

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

@feep
Copy link

feep commented Mar 13, 2024

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.

@Avi-D-coder
Copy link

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