Section 11.11. Assignment of Multiple Attributes

11.11. Assignment of Multiple Attributes

Recall from Chapter 7 that it is possible to assign multiple values in a single command by using a list:

 set {x, y, z} to {1, 2, 3}

You can use this syntax to fetch multiple attributes , using either tell or of:

 tell application "Finder"     set {x, y} to {name, comment} of folder 1 end tell {x, y} -- {"Mannie", "howdy"}

That code fetches name of folder 1 and comment of folder 1 from the Finder in a single command.

You can use this construct to set multiple properties as well, but only in a tell block (trying to do it with of will cause a runtime error):

 tell application "Finder"     tell folder "Mannie"         set {comment, name} to {"zowie", "Jack"}     end tell end tell

Be careful of the order in which you list the properties when assigning to them. The values are assigned from left to right. This wouldn't have worked:

 tell application "Finder"     tell folder "Mannie"         set {name, comment} to {"Jack", "zowie"} -- error     end tell end tell

That code sets the name first, and afterwards there is no longer a folder "Mannie" to set the comment of, so the attempt to set the comment of folder "Mannie" causes a runtime error.

AppleScript. The Definitive Guide
AppleScript: The Definitive Guide, 2nd Edition
ISBN: 0596102119
EAN: 2147483647
Year: 2006
Pages: 267
Authors: Matt Neuburg

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: