Got a question about using tell statements in scripts.
I do understand about tell blocks to control applications.
example:
tell application "finder"
etc…etc…
Thats simple enough, what i want to know is how will i know when to use a tell statement
to talk to a specific item.
example:
tell document 1
example
tell window 1
etc… etc…
i’ve seen this across many scripts across this forum and always wondered.
My guess is when i’m scripting and i run out of ideas with all the different syntax i’ve tried that i need to talk
directly to the object. so i use:
tell folder 1
or something
like this.
Is this a totally dumb ass question or am i making sense! an help with understanding this would be appreciated…Thanks
The most common use for doing this is when you want to refer to a particular object multiple times.
Instead of something like this.
tell application "iTunes"
set trackName to name of current track
set trackArist to artist of current track
set trackAlbum to album of current track
end tell
.you can use this:
tell application "iTunes"
tell current track
set trackName to name
set trackArist to artist
set trackAlbum to album
end tell
end tell
A method that Kai often uses to compress scripts to one line, e.g., this for a Finder sortable date with a cascade of tells:
tell (current date) as string to tell my date it to tell (year * 10000 + (its month) * 100 + day) as string to text 1 thru 4 & "." & text 5 thru 6 & "." & text 7 thru 8