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
  •  | 
  •  

Domanda

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
È stato utile?

Soluzione

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

Altri suggerimenti

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!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top