Skip to content

Instantly share code, notes, and snippets.

@aahung
Created June 26, 2019 08:16
Show Gist options
  • Save aahung/94e381cdd4baf16270ef41acd250b97b to your computer and use it in GitHub Desktop.
Save aahung/94e381cdd4baf16270ef41acd250b97b to your computer and use it in GitHub Desktop.
Open current folder in Kitty (apple script)
on alfred_script(q)
tell application "Finder"
set pathList to (quoted form of POSIX path of (folder of the front window as alias))
set textToType to "clear; cd " & pathList
end tell
tell application "System Events"
set isRunning to (exists (processes where name is "kitty"))
end tell
tell application "kitty" to activate
set activeApp to ""
repeat while activeApp is not "kitty"
tell application "System Events"
set activeApp to name of first application process whose frontmost is true
end tell
end repeat
if isRunning then
tell application "System Events"
keystroke "n" using {command down}
end tell
end if
tell application "System Events"
keystroke textToType
keystroke return
end tell
end alfred_script
@edeetee
Copy link

edeetee commented Jan 6, 2024

This is the one

@edeetee
Copy link

edeetee commented Jan 6, 2024

Edited mine like this to handle if no finder window or no path.

I just have this as an automator service that I trigger with the key combo "ctrl+~"

tell application "Finder"
	set textToType to ""
	try
		set pathList to (quoted form of POSIX path of (folder of the front window as alias))
		set textToType to "clear; cd " & pathList
	end try
	
end tell

tell application "System Events"
	set isRunning to (exists (processes where name is "kitty"))
end tell

tell application "kitty" to activate
set activeApp to ""

repeat while activeApp is not "kitty"
	tell application "System Events"
		set activeApp to name of first application process whose frontmost is true
	end tell
end repeat

if isRunning then
	tell application "System Events"
		keystroke "n" using {command down}
	end tell
end if

if textToType is not "" then
	tell application "System Events"
		keystroke textToType
		keystroke return
	end tell
end if

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment