Jump to content

When opening a Terminal prompt, the first action launches the Terminal app but doesn't run the command


Recommended Posts

Posted

Using Alfred 5.5.1 [2273] on macOS Sequoia 15.2.

 

Steps to reproduce: Check that the Terminal app is not running. Launch Alfred and type `>ls ~` (or any other terminal command), then select the "Run command in Terminal" action.

Expected outcome: The Terminal app opens and runs the `ls ~` command.

Actual outcome: Terminal app launches (i.e. appears in the Dock) but no windows open. If you run the command from Alfred a second time, a window opens and the command runs.

 

This issue has been going on for at least a month now - possibly longer, I'm afraid I've not been keeping track properly, nor can I remember if there was a specific update to macOS or Alfred coinciding with the bug happening. I am able to reproduce the issue consistently.

Posted

What happens if you do run the command, and instead of running it a second you click the Terminal icon in the Dock? Does the window have the command in there or not?

Posted

Change it to Custom and use this code:

 

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


What’s the behaviour now?

 

Also, what’s your Mac model?

Posted
on alfred_script(q)
  tell application "Terminal"
    if running then do script ""
    activate
    activate
    delay 1
    do script q in window 1
  end tell
end alfred_script

 

How about that?

Posted

That script has the same result, but I've got a little closer to the problem:

 

If I have an open Terminal window, then quit Terminal, and run the command in Alfred, everything works as expected.

If I have an open Terminal window, close that window, then quit Terminal, I end up with the bug I described originally.

 

So it seems to be an issue with opening Terminal when it is not launching a restored session.

Posted

That’s a good insight, my next suggestion was precisely going to be that there might be something funky going on with your Terminal settings. I can’t reproduce your issue, so check what you can change.

 

One thing which might work for you is:

 

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

 

But that may leave you with an extra window in some situations. It might be possible to write the exact AppleScript for your situation but that’s extra hard without being able to reproduce your problem.

Posted

That latest script seems to work okay, so I'll put that in as a workaround for now - thank you!

 

There's not much in the way of Terminal settings that seem useful - it's set to open new window at startup and I can't see much else relevant. I suppose it's just a case of trying again on the next macOS!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...