Last active
June 10, 2025 17:51
-
-
Save philocalyst/2c60b30d8ba430de96e74d12bcc8c67f to your computer and use it in GitHub Desktop.
Alfred Wezterm Applescript (For terminal feature)
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I’ll add some error handling… I believe it’s a matter of ensuring the application is already open. Need a few hours.