What's the difference between “tell … to” and “of …”?

Hey everyone, something has been bugging me for a while now and I don’t know the reason for it. As far as I always thought, it is possible to use the following 3 wordings interchangeably:
b[/b] tell object to set property to value
b[/b] set property of object to value
b[/b] set object’s property to value

Am I right when assuming those 3 are identical? If so, what’s the deal with this example?

tell application "Finder"
	set SomeDir to "DirName"
	set FinderWindow to Finder window SomeDir
	set bgPic to document file "background.jpg" of folder SomeDir of startup disk
	tell FinderWindow to set background picture of icon view options to bgPic	-->  doesn't work  <--
	set background picture of icon view options of FinderWindow to bgPic		-->  works fine  <--
end tell

Aesthir

Model: iMac 7,1
AppleScript: AppleScript 2.2.1
Browser: Firefox 11.0
Operating System: Mac OS X (10.7)

Hi,

in principle the three forms are identical, but in your example the reference chain is

set property of another_object of object to value

I haven’t tested it, but this should work

tell icon view options of FinderWindow to set background picture to bgPic 

or

tell FinderWindow's icon view options to set background picture to bgPic 

This line is simply missing the self-referential “its”.


tell application "Finder"'s window "DirName" to set its icon view options's background picture to (choose file)

Now, how do I remove the stupid picture I just put there? :stuck_out_tongue:

Great! Thanks Stefan & Marc :smiley: Both of your solutions work perfectly!

Aesthir