Skip to content

Instantly share code, notes, and snippets.

@philocalyst
Last active June 10, 2025 17:51
Show Gist options
  • Save philocalyst/2c60b30d8ba430de96e74d12bcc8c67f to your computer and use it in GitHub Desktop.
Save philocalyst/2c60b30d8ba430de96e74d12bcc8c67f to your computer and use it in GitHub Desktop.
Alfred Wezterm Applescript (For terminal feature)
on alfred_script(query)
try
-- Check if WezTerm is running
set weztermRunning to false
tell application "System Events"
if (name of processes) contains "wezterm-gui" then
set weztermRunning to true
end if
end tell
-- Launch WezTerm if not running...
if not weztermRunning then
tell application "WezTerm" to launch
-- Wait a moment for WezTerm to fully and completely launch
delay 2
end if
-- Activate WezTerm (Open a dialog)
tell application "WezTerm" to activate
-- Create new terminal session
try
do shell script "/Applications/WezTerm.app/Contents/MacOS/wezterm cli spawn"
on error errMsg
display dialog "Failed to create new WezTerm session: " & errMsg buttons {"OK"} default button "OK"
return
end try
-- Send commands to WezTerm
set commandList to paragraphs of query
repeat with command in commandList
if command as string is not "" then -- Skip empty lines
try
do shell script "echo " & quoted form of command & " | /Applications/WezTerm.app/Contents/MacOS/wezterm cli send-text --no-paste"
on error errMsg
display dialog "Failed to send command '" & command & "': " & errMsg buttons {"OK"} default button "OK"
end try
end if
end repeat
on error errMsg
display dialog "WezTerm Alfred Script Error: " & errMsg buttons {"OK"} default button "OK"
end try
end alfred_script
@philocalyst
Copy link
Author

I’ll add some error handling… I believe it’s a matter of ensuring the application is already open. Need a few hours.

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