How the hell! do i Tell.........

Hi

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

cheers

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

Pidge1,

I may be mistaken, but it seems that you use something like:

tell document 1

when you don’t want to use several lines of code targeting “document 1”

Like:

make text frame in document 1
make new rectangle in document 1
set fill color of path item 1 of document 1 to blah blah

You put all of this in the tell statement partly to avoid having to describe the target every time you need it.
(Well, that’s what the voices tell me):smiley:

PreTech

Bruce beat me to it.

Glad to here those voices are giving out good information PreTech. :slight_smile:

A thought. note that something like this won’t work, because “current track” and "artwork
are terms which belong to iTunes.

tell artwork 1 of current track of application "iTunes"
	set artKind to kind
	set artFormat to format
end tell

This should work though:

tell application "iTunes" to tell artwork 1 of current track
	set artKind to kind
	set artFormat to format
end tell

Edit: I knew Adam would have a date example. :wink:

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

Thanks Guys!!

I get the idea now…
it makes total sense

cheers

The only adder to this, Pidge1, is that when you have to refer back to the object being told, the reference is it