Re: "tell application" without starting application?
Re: "tell application" without starting application?
- Subject: Re: "tell application" without starting application?
- From: Paul Berkowitz <email@hidden>
- Date: Wed, 27 Nov 2002 20:58:11 -0800
On 11/27/02 7:53 PM, "Duncan Cowan" <email@hidden> wrote:
>
Thanks Paul, I think I see what you mean.
>
>
1. I should have moved the iTunes tell block outside of the Finder tell
>
block and retrieved the process list beforehand and stored it as a variable
>
(correct term?).
>
>
So I could do something like this?
>
>
on dothis()
>
tell application "iTunes"
>
-- do itunes stuff here.
>
end tell
>
end dothis
>
>
>
tell application "Finder"
>
set allProcs to name of every process
>
-- do any other finder stuff here
>
if allProcs contains {"iTunes"} then
>
my dothis()
>
else
>
display dialog "itunes is NOT running"
>
end if
>
end tell
Yes. But Rob was correct in that just setting a boolean variable (i.e. true
or false) in your Finder block to 'exists process "iTunes"' is more
efficient (save 1/10th of a second, why not?). I have avoided that by habit
since some OS 9 version of the Finder may have had trouble with it (or I may
be imagining it).
>
>
2. This is a little clouded - only because I'm not sure where in your script
>
you made the single item list. Does it occur when you bracketed {"iTunes"} ?
Yes. That's a single-item list. You just used the string "iTunes". (As Rob
says, you avoid the issue if using his 'exists' method, but you're going to
run into it again soon enough.)
>
I can see what you mean by the coercion issue as "display dialog allProcs"
>
tossed up an error.
Right. But not exactly the same issue: display dialog requires a string and
can't coerce a list to a string, so you get an error. Just coerce the list
to a string and display dialog will work OK.
set AppleScript's text item delimiters to {", "}
display dialog (allProcs as string)
set AppleScript's text item delimiters to {""}
would display a "string list" separated by commas. (Actually, since it's a
single-item list it makes no difference what the delimiter is, but for
multi-item lists you'd probably want either ", " or (return) as delimiter.)
If you want to check up on the class, you'll have to coerce the class to a
string as well to get display dialog to acknowledge it:
set procsClass to class of allProcs
--> list
set procsClass to procsClass as string
--> "list"
display dialog procsClass
("list")
set ituneClass to class of "iTunes"
--> string
set ituneClass to ituneClass as string
--> "string"
display dialog ituneClass
("string")
If you used 'log' in Script Editor, or got a better editor like Smile, you
could step through individual lines of scripts to check on their results,
and not have to depend on strings for display dialog. display dialog is not
too useful as a debugger in this sort of circumstance: it just made us go
around in circles!
But I was talking about the reverse case: when using the 'contains' operator
(or 'is in', its converse):
"a long string" contains "string" -- same class [string]
--> true
{"Many", "separate", "strings"} contains {"strings"} -- same class
[list]
--> true
{"Many", "separate", "strings"} contains "strings" -- coercion, special
case [list on left, coercion of string to list on right]
--> true
tell application "Outlook Express"
{message id 12345, message id 12346, message id 12347} contains
message id 12345 -- list on left side, message class on right side
--> ERROR: "Can't make <<class inm >> id 12345 into a vector."*
{message id 12345, message id 12346, message id 12347} contains
{message id 12345} -- both sides lists
--> true
end tell
(* a vector is a type of list.)
--
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.