Last active
December 29, 2023 14:03
-
-
Save SebastienWae/4211d4b2b4c8abde449d69bf9c40175f to your computer and use it in GitHub Desktop.
Implementation of Kitty remote control for Alfred custom terminal
This file contains hidden or 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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