Skip to content

Instantly share code, notes, and snippets.

@SebastienWae
Last active December 29, 2023 14:03
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SebastienWae/4211d4b2b4c8abde449d69bf9c40175f to your computer and use it in GitHub Desktop.
Save SebastienWae/4211d4b2b4c8abde449d69bf9c40175f to your computer and use it in GitHub Desktop.
Implementation of Kitty remote control for Alfred custom terminal
use framework "Foundation"
use scripting additions
-- https://forum.latenightsw.com/t/reading-json-data-with-nsjsonserialization/958/2
on readJSON(strJSON)
set ca to current application
set {x, e} to ca's NSJSONSerialization's JSONObjectWithData:((ca's NSString's stringWithString:strJSON)'s dataUsingEncoding:(ca's NSUTF8StringEncoding)) options:0 |error|:(reference)
if x is missing value then
error e's localizedDescription() as text
else
item 1 of ((ca's NSArray's arrayWithObject:x) as list)
end if
end readJSON
on alfred_script(query)
try
set kittyWindows to do shell script "/Applications/Kitty.app/Contents/MacOS/kitty @ --to unix:/tmp/mykitty ls"
set kittyWindows to readJSON(kittyWindows)
on error
set kittyWindows to {}
end try
do shell script "open -a kitty"
tell application "kitty" to activate
if (count of kittyWindows) > 0 then
do shell script "/Applications/Kitty.app/Contents/MacOS/kitty @ --to unix:/tmp/mykitty new-window --new-tab"
end if
set commandList to paragraphs of query
set CR to " \\x0d"
repeat with command in commandList
do shell script "/Applications/Kitty.app/Contents/MacOS/kitty @ --to unix:/tmp/mykitty send-text " & command & quoted form of CR
end repeat
end run
@SebastienWae
Copy link
Author

SebastienWae commented Jun 7, 2020

Implementation of Kitty remote control for Alfred custom terminal

Based on @pyrho idea, see his blog post for more detail on how to setup: https://25.wf/posts/2020-03-23-alfred-kitty.html

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