Current Application problems

I have a problem where if I did

delay 1
tell current application to display dialog "Hi."

from Applescript Editor, and quickly moved to Safari before the dialog, Applescript Editor would still display the dialog. Is this a problem?

Hi, Dylan.

It’s right. The current application is the application running the script.

Oh! So current application doesn’t mean the frontmost application, but IT. OK.

you can get the front most application with this code:

tell application "System Events" to get name of some process whose visible is true and frontmost is true

Hope it helps,
ief2

Or:

tell application (path to frontmost application as Unicode text) to get name

As from SL (I think), applications have a ‘frontmost’ property as standard. (The Finder has had one for ages.) You can’t filter for it, but it’s a convenient way to tell if a particular application is frontmost.

Hello

I found this explanation of the “double tell block” here at macsripter.net truly helpful on that subject (though it might need an update on the “frontmost” property.

Best Regards

McUsr

From Leopard. The good news is it won’t launch an app to find out if it’s frontmost, unlike properties built in to apps.