current application in Os x

Hi
when i try to use the this line below


set Xapplication to current application

It gives Xapplication the value “current application”
and not the name of the current application

Thanks guys :lol:

This works on my machine (OS X 10.2.3, System Events 1.2).

tell application "System Events"
	set frontApp to item 1 of (every application process whose frontmost is true)
end tell

Thnaks Rob

I changed it a tad to get what i needed it works great


tell application "System Events"
	set Xappliction to the name of the (item 1 of (every application process whose frontmost is true))
end tell

:smiley: :smiley:

Just a note.
“current application” is an applescript constant, and it will return information about “guy running this code”. If from an applet, you’ll get «class scpt» (script); if from a script editor or a script menu, «class capp» (application), etc. And you won’t get more info about “current application”…
“frontmost application” is a different concept: the frontmost app :wink:
If you run this code saved as an applet, you’ll see clearly the differences:

repeat
	delay 1
	set x to (path to current application) as text
	tell application (path to frontmost application as text) to display dialog x
	set x to (path to frontmost application) as text
	tell application (path to frontmost application as text) to display dialog x
end repeat

If frontmost application is the applet, you’ll get the same result. If you switch to the Finder, you’ll get the path to the applet and the path to the Finder (the frontmost app just now).
“frontmost application” is a constant, too. To extract some extra info, you need third-party help: system events, the Finder or any osaxen. A slightly quick way to get the name of the “frontmost application” could be:

name of (info for (path to frontmost application))

-- > two calls to standard additions
-- > or:

set AppleScript's text item delimiters to ":"
set app_name to text item -1 of (path to frontmost application as text)
set AppleScript's text item delimiters to {""}

For some folks enjoying nonsensical stuff, calling System Events gives me 190 milliseconds/run; first way through standard additions (two calls) 30,7 milliseconds/run; and third way (TIDs) 6,7 milliseconds/run (nearly 30 times faster than system events call)

Hey, that’s quite an improvement! Can you work the same kind of magic to improve my income and make it 30 times more effective? :wink:

:lol: Maybe there are some handlers out there… I’d take a look at SB…

It is necessary to tell the current application: “What’s your name”. Then you can create reference to application itself using the keyword application


set XapplicationName to name of current application
set Xapplication to application XapplicationName

Or, get application directly (using get keyword):


set Xapplication to application (get current application's name)