Search code examples
terminalapplescriptalfred

How does one keep Alfred 2 from opening and entering your Terminal command in a new window when Terminal is already open?


What changes do I make to make it so that it only opens a window if Terminal isn't already running but otherwise, enters the command in the open window? I'm thinking control flow, conditional jawn. I'm not sure how to write it out though.

Thanks, TJ

The script is as follows:

on alfred_script(q)
    tell application "Terminal"
        activate
        do script q
    end tell
end alfred_script

Solution

  • Try:

    on alfred_script(q)
    tell application "Terminal"
        if not (exists window 1) then reopen
        activate
        do script q in window 1
    end tell
    end alfred_script