Applescript - activate background application doesn't work

I think the problem is.. Telling an application to activate, is handled by "Standard Additions", but you are asking "System Events" to handle that action.

tell application "System Events" to set AppName to name of ¬
    every process whose background only is false
tell application (some item of AppName) to activate

Let me tell you a story:

One parent got up and called to three children:

  • Ace - wake up and go bring me an apple
  • Deuce - wake up and go bring me an apple
  • Trey - wake up and go bring me an apple

That parent was happy to have three apples and everyone out of bed.

The other parent said:

  • Trey - wake up and go bring me an apple (or they think they asked Trey - they're not really sure they were specific about what or who was asked)

Does this match what "doesn't work" for you?

If so - awesome. If not, you'll want to step through each script in Script Editor and see where your programs go "off script". I would also encourage a look at https://latenightsw.com Script Debugger - it runs some basic functionality for free, but If you value your time more than you do stepping through scripts in Apple's more basic editor, it may be worth the $$ to you for the full version.

Also, a book on iteration or loops might be a good place to go if everything wasn't clear. Don't feel bad, this is a great place to stumble and learn - once you get loops, you'll be able to do amazing things in any scripting language - not just AppleScript.


I was trying to click the "OK" button on Kontakt in the background while I worked. This solved my issue:

tell application "System Events"
    if exists of application process "Kontakt 5" then
        tell application "Kontakt 5.6.0" to activate
        delay 0.5
        repeat
            try
                click UI element "OK" of window 1 of application process "Kontakt 5"
            end try
        end repeat
    end if
end tell