What is Best Method for Current Application?

Are there any advantages of one method over the other?
Or is there a better way?

### WHICH IS BEST? ###

set currentApp to path to frontmost application as text
# OR
tell application "System Events"
  set currentApp to name of first application process whose frontmost is true
end tell

--- For use with Dialogs like this ---

tell application currentApp
  display dialog "some message"
end tell

If you can do something without involving a target app, you’re potentially avoiding an authorization dialog for an applet (depending on the rest of the script, of course). That would be the clincher for me.

Thanks Shane. I agree with that, but how do we implement it?

If I need to use a display dialog, I would generally want to do it using the frontmost app, right? So how can we avoid using a target app?

You can’t avoid using a target app, but you can avoid an authorization dialog for System Events.

So does that mean option #1, which does NOT use System Events, is the best choice?

set currentApp to path to frontmost application as text

That’s my feeling, yes.

1 Like