Re: Change Character
Re: Change Character
- Subject: Re: Change Character
- From: kai <email@hidden>
- Date: Sun, 5 Jun 2005 23:24:12 +0100
On Sunday, June 5, 2005, at 11:16 am, Kim Hunter wrote:
Thankyou \
Solved every thing
What is the deal with the My bit
I see that you've already had some excellent replies since you posted
your question Kim, so I won't duplicate. However, I wondered if the
following snippet, using Finder as an example application, might help
to illustrate some of the points made:
-----------------
to displayMessage(msg)
activate -- me (the application running the script)
display dialog msg
end displayMessage
tell application "Finder"
activate -- Finder
display dialog "(1) Finder was told: display dialog."
try
set msg to "(2) Finder was told: displayMessage."
displayMessage(msg)
on error errorMessage number errorNumber
beep
display dialog msg & return & return & ¬
"This returned an error number " & errorNumber & ":" & return &
errorMessage
end try
tell me to displayMessage("(3) Finder was told: tell me to
displayMessage.")
displayMessage("(4) Finder was told: displayMessage of me.") of me
my displayMessage("(5) Finder was told: my displayMessage.")
end tell
displayMessage("(6) I (the script) was told: displayMessage.")
-----------------
You'll see that the last example, (6), needs no redirection because it
falls outside the Finder tell block. (One-liners aside, it's generally
a good idea to end a tell block as soon as possible, rather than load
it up with a bunch of core AppleScript statements - even if that means
opening another tell block later on...)
-----------------
Applications can be considered specialists: they're designed to perform
certain actions rather better than others. So they'll usually respond
to the commands and keystrokes (not to mention AppleEvents) that they
understand - and either ignore or complain about those they don't. In
fact, with regard to their reaction to external requests and demands,
they're probably not that different from you and me. ;-)
Just for fun, the following example attempts to echo a 'real-world'
scenario, in which 3 "people" (script/objects) each try to accomplish a
series of tasks. (For demonstration purposes, I've used script objects
rather than applications - but the general principle is similar.)
A couple of the "players", an electrician and a plumber, have unique
skills that allow them to perform certain specialised operations - like
fixing faulty wiring or mending leaky pipes. On the other hand, my (the
main script's) own skills are rather more generalised - although I'm
considered quite handy when it comes to making tea... (Mr Tea - are you
listening?) ;-)
In spite of the need for a particular job to be accomplished by the
appropriate specialist, all those (people/objects) involved understand
the 'finishOff' command - even if they might respond to it in their
own, individual way. However, whenever a job is passed to some
person/object that doesn't understand how to deal with it, an error
(signified by a beep) occurs.
Rather than concern yourself too much with the the script's
construction, it's probably better to regard it merely as intended: a
somewhat playful demonstration of some of the general principles
discussed.
Um... apologies for the length, folks:
-----------------
script Electrician
to fixWiring thru specialSkills
display dialog my name & specialSkills with icon 1
end fixWiring
to finishOff by clearingUp
display dialog my name & clearingUp & "...\"" with icon 1
end finishOff
end script
script Plumber
to fixLeaks thru specialSkills
display dialog my name & specialSkills with icon 1
end fixLeaks
to finishOff by clearingUp
display dialog my name & clearingUp & "...\"" with icon 1
end finishOff
end script
property knowHow : ": \"I can fix the "
property noWay : ": \"Doh! I don't know how to fix "
property anyWay : ": \"Now I'll "
property goodNews : "!\" :)"
property badNews : ".\" :("
property people : {Electrician, Plumber, me}
property jobList : {"faulty wiring", "leaking pipes", ""}
property lastJobs : {"clear away all the cables", ¬
"mop up all the water", ¬
"make a tasty cuppa"}
to finishOff by makingBrew
display dialog "Me" & makingBrew & goodNews with icon 1
end finishOff
repeat with someJob from 1 to count jobList
set thisJob to item someJob of jobList
repeat with thisItem from 1 to count people
set thisPerson to item thisItem of people
set lastJob to item thisItem of lastJobs
tell thisPerson to try
if thisJob is "faulty wiring" then
fixWiring thru knowHow & thisJob & goodNews
else if thisJob is "leaking pipes" then
fixLeaks thru knowHow & thisJob & goodNews
else
finishOff by anyWay & lastJob
end if
on error number errorNumber from somePerson
if errorNumber is -128 then error number errorNumber
if somePerson is me then set somePerson to {name:"Me"}
beep
display dialog somePerson's name & ¬
noWay & thisJob & badNews with icon 2
end try
end repeat
end repeat
-----------------
---
kai
_______________________________________________
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