Skip to content

Instantly share code, notes, and snippets.

@titancode
Created March 7, 2026 19:54
Show Gist options
  • Select an option

  • Save titancode/7373f0b63851787e6cb26f8fd594d017 to your computer and use it in GitHub Desktop.

Select an option

Save titancode/7373f0b63851787e6cb26f8fd594d017 to your computer and use it in GitHub Desktop.
Alfred workflow AppleScript for creating or resuming a Yatoro screen session in Ghostty
-- Create or resume a GNU screen session named "music" in Ghostty.
-- If the session does not exist, launch Yatoro and run a list of startup commands.
-- Designed for use in an Alfred workflow.
-- It's mostly created by ChatGPT
on run argv
if (count of argv) is 0 then return
set actionName to item 1 of argv
if actionName is "create_music_screen" then
my createMusicScreenSession()
else if actionName is "resume_music_screen" then
my resumeMusicScreenSession()
end if
end run
on createMusicScreenSession()
if my musicScreenExists() then
my openGhosttyAndRunCommand("screen -D -RR music")
else
-- Each item is {command, delayAfter}
set startupCommands to {¬
{"yatoro", 3}, ¬
{":your first command here", 2}, ¬
{":your second command here", 2}, ¬
{":your third command here", 0} ¬
}
tell application "Ghostty"
set newWin to new window
activate window newWin
delay 1.5
set t to first terminal of newWin
my sendCommandToTerminal(t, "screen -S music", 0.5)
repeat with stepItem in startupCommands
set stepData to contents of stepItem
set theCommand to item 1 of stepData
set thePause to item 2 of stepData
my sendCommandToTerminal(t, theCommand, thePause)
end repeat
end tell
end if
end createMusicScreenSession
on resumeMusicScreenSession()
if my musicScreenExists() then
my openGhosttyAndRunCommand("screen -D -RR music")
else
my createMusicScreenSession()
end if
end resumeMusicScreenSession
on openGhosttyAndRunCommand(theCommand)
tell application "Ghostty"
set newWin to new window
activate window newWin
delay 1.5
set t to first terminal of newWin
my sendCommandToTerminal(t, theCommand, 0)
end tell
end openGhosttyAndRunCommand
on sendCommandToTerminal(theTerminal, theCommand, pauseAfter)
tell application "Ghostty"
input text theCommand to theTerminal
send key "enter" to theTerminal
end tell
if pauseAfter > 0 then delay pauseAfter
end sendCommandToTerminal
on musicScreenExists()
try
set resultText to do shell script "screen -list | grep -E '[[:space:]]+[0-9]+\\.music([[:space:]]|$)' || true"
return resultText is not ""
on error
return false
end try
end musicScreenExists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment