Applet hangs until made frontmost

I wrote the applet below as an Accounts prefPane Login Item to in turn launch my favorite apps because the “launch” command opens the apps in the background, letting me get on with work enduring less intrusion than having to wait on a bunch of Login Items to settle down. My problem is twofold:

  1. The applet just hangs forever until it is made the frontmost app. Why won’t it do its thing in the background? (Curiously, on another Mac running the same Tiger 10.4.9, it comes up at login as frontmost, so the problem doesn’t arise. I wonder why?)

  2. The first line, aspiring to be a workaround, doesn’t bring it to the front. How come?

tell application “System Events” to set frontmost of me to true

display dialog ¬
“Your favorite login apps will launch unless you cancel within ten seconds” giving up after 10

tell application “[my app]” to launch
– (etc., etc.)

I don’t mean to be curt or rude if this is not the answer…

tell me to activate

… will bring your script or app to the front for attention (pretty) reliably.


That worked, thanks!
Funny though, months ago that was the first thing I tried and it didn’t work, which is why I tried other ways, including the “tell application ‘System Events’ to set frontmost of me to true”
Don’t know why the latter doesn’t work now, or why your way didn’t work earlier, but I guess the explanation forever will be buried in my interim 10.4.5-to-10.4.9 update and umpteen haxies I have no business running.
Thanks again, Peter!

I spoke too soon!
It worked that one time, but now it’s back to its old ways:
After every restart, the applet ends up in the background, its dock icon bouncing (announcing my display dialog), and eventually I get an “Apple Event timed out” error.
The question would appear to be, why won’t my line …

display dialog ¬
“Your favorite login apps will launch unless you cancel within ten seconds” ¬
giving up after 10

… proceed until my applet is brought frontmost?
It appears that is the only line that hangs when the applet is in the background:
When I deleted that line from my applet and restarted, it still ended up in the background (there are a couple of other Accounts prefPane Login items that accompany my applet), all the rest of the lines (all “tell app '[xxx]'to launch” commands) get executed.
What do you think?

Hi Schmye Bubbula,

I duplicated something like what you’re describing, but didn’t wait for the timeout error. Still thinking of a good workaround.

You might try placing all your other tell app “someapp” to launch scripts in the same script as the one that is hanging. Another way might be to check the Hide checkbox in System Preferences for your other login items scripts. Perhaps the best way might be to make your other script apps that don’t have dialogs background only. Lastly for now, you can try placing your dialog in a tell block:

tell app “System Events”
display dialog “whatever” giving up after 10
end tell

What is happening is that all login items are opened at about the same time. When it reaches the other login items that aren’t hangining, they are brought to the front and your hanging app is in the back. Then the hanging app hangs when it reaches the display dialog.


You nailed it, kel. Thanks!

The workaround is for my applet to tell System Events to do the display dialog instead of my applet telling itself to do so.

That way, the display dialog appears in the Finder or in whatever other app among the Accounts prefPane Login items happens to land frontmost. Problem solved.

Still curious why a display dialog in an applet running in the background would hang and eventually cause an Apple Event timed out error. Seems like with my “giving up after” qualifier, it should just dismiss itself and continue running the rest of the script. Maybe it’s an AppleScript bug?