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

StackOverflow https://stackoverflow.com/questions/22290329

  •  12-06-2023
  •  | 
  •  

Question

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
Was it helpful?

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

OTHER TIPS

Check this: https://github.com/miromannino/alfred-new-terminal-window

It opens a new Terminal/iTerm window in the current space. Holding the alt key, the new window is also opened opened in the current frontmost Finder folder.

It is really faster compared to others, really important for me since I use the terminal for almost everything! :)

Hope it helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top