Re: Name of Active Process
Re: Name of Active Process
- Subject: Re: Name of Active Process
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 17 Jun 2004 13:33:07 -0700
On 6/17/04 12:49 PM, "John Baltutis" <email@hidden> wrote:
>
Can anyone explain why this only returns "Script Editor" no matter what
>
number is used after process:
>
>
tell application "System Events" to get name of process 1 whose frontmost
>
is true
>
tell application "System Events" to get name of process 300 whose frontmost
>
is true
>
>
or errors with when any alpha number greater than tenth is used in the
>
second example below: both running in script editor;
>
>
tell application "System Events" to get name of first process whose
>
frontmost is true
>
(where the event log shows it converted to: get name of process 1 whose
>
frontmost = true)
>
>
tell application "System Events" to get name of eleventh process whose
>
frontmost is true
>
->"Syntax Error-A class name can't go after this identifier-highlighting
>
eleventh process" ?
>
>
Also,
>
>
tell application "System Events" to get name of process whose frontmost is
>
true
>
->AppleScript Error: Can't get name of process.
This is just AppleScript nonsense/inconsistency. System Events'
inconsistency, actually, not the language itself, I'd guess. What else is
new?
By rights, if the number, cardinal or ordinal, is greater than 1 or 'first',
it should error, in my opinion.
It's a little complicated. Since "Script Editor" is the first, last and only
process whose process is currently true, you get that as an answer no matter
what number you ask for. Only one process can be 'frontmost', and that's it.
It's a coercion. It's making up for the fact that AppleScript doesn't allow
you to ask for :
tell application "System Events" to get name of the [only] process whose
frontmost is true
or
tell application "System Events" to get name of the frontmost process
which is what - honestly - you'd like to ask it in English. By AppleScript
syntax, you can only ask for 'every' process, or one of those terms that
acts on a list, such as first, last, middle, or by index : 1,, 2,
3....300..., or by "English" ordinal : first, second, third...tenth. Since
only first makes any sense here, everything else is getting coerced to
first. (The Finder, and now System Events, likes helping out newbies.) In my
opinion, it should error, not coerce to 'first', but there you are.
The last syntax error is much simpler. The AppleScript keywords for
"English" ordinals: first. second, etc. only go up to 'tenth'. (See the
AppleScript Language Guide.) So 'eleventh' is a variable, which can't be
followed in this syntax by 'process': " A class name can't go after this
identifier" is the right error message. If you have good AppleScript
formatting you'll see that 'eleventh' is formatted as a variable, not an
AppleScript language keyword. However
tell application "System Events" to get 11th process whose frontmost is
true
works just fine. You'll note that if you try '21th' it will change it to
'21st' and still "work" (Script Editor yet again). You can go on using
ordinal numerals, including 300th, til kingdom come.
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.