Jump to content

Close terminal after alfred terminal command

Recommended Posts

Dear community,


I would like the terminal window to close after Alfred executed the terminal command. I tried this as follows:


on alfred_script(q)
    do shell script & q
end alfred_script



 on alfred_script(q)
    tell application "Terminal"
        do script q
        osascript -e 'tell application "Terminal" to quit'
    end tell
end alfred_script


But unfortunatley both ways are not working.


Does somebody maybe know a solution,


Thanks in advance,



Share this post

Link to post

osascript -e '{{command}}' is what you’d do to call AppleScript from bash. Here, it makes no sense. Replace the whole line osascript -e 'tell application "Terminal" to quit' with just quit, and it will work.

But if you want terminal to quit immediately, then why are you opening it at all? You likely want a Run Script instead.

Share this post

Link to post
6 hours ago, Stooovie said:

Why close immediately?


It doesn't close immediately. do shell script doesn't return until the script completes, so the quit command isn't even sent until the shell script has finished.

Also, nobody mentioned long-running commands. Plenty of shell commands finish extremely quickly.

Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...