Re: Finder in processes false ?
Re: Finder in processes false ?
- Subject: Re: Finder in processes false ?
- From: Christopher Nebel <email@hidden>
- Date: Tue, 11 Oct 2005 15:00:02 -0700
On Oct 11, 2005, at 7:34 AM, Jay Louvion wrote:
Anyone can show me how dumb I am for not getting why this returns
“false” ?
tell application "System Events"
set theProcesses to (list processes as list)
if theProcesses contains "Finder" then
set op_state to "True"
else
set op_state to "False"
end if
end tell
Well, there are two reasons this doesn't work. Several people have
pointed out that a "process" object is not the same thing as a
string, so comparing them will always return false. The more serious
problem is that "list processes as list", while syntactically and
semantically well-defined, doesn't do even remotely what you think it
does. [1] This is about the point where Matt N. would advise you to
go read a book and actually learn AppleScript instead of thinking
that it's Just Like English™ and hoping for the best.
What you actually meant when you said "list processes as list" was
simply "processes" (or the equivalent "every process"); what you
meant when you said 'if theProcesses contains "Finder"' was something
more like 'if name of every process contains "Finder"', and what you
were really trying to do was to ask 'exists process "Finder"'. And
if all you *really* wanted to do was make sure the Finder was running
so you could launch it before telling it to do something, then all
you needed to say was 'tell application "Finder"', since AppleScript
will take care of launching applications for you.
--Chris Nebel
AppleScript and Automator Engineering
[1] The first "list" is not a command, it's a class name -- "list
processes" is really an object specifier of type "list" with selector
data of "processes", which is evaluated by System Events, so you get
'list {application process "loginwindow" of application "System
Events", ...} of application "System Events"'. Ordinarily, this
can't be evaluated and would generate an error, but then the "as
list" kicks in. AppleScript can turn any value into a one-item list,
and that's what it does; its habit of only evaluating object
specifiers lazily then takes over, so you get a result of '{list
{application process "loginwindow", ...} of application "System
Events"}'.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden