An alias is a way of referring to a file, folder, or volume in a script. It has the unique property that if the item is moved after the alias is set, the alias will keep track of it. This isn’t quite the same as an “alias” in the Finder’s user interface, which is known in Finder scripting as an ‘alias file’.
The expression ‘as alias’ is a “coercion”. It produces an alias version of some other means of referring to a file, folder, or volume.
The ‘selection’ in Finder scripting is a list of all the items that are selected. If only one item is selected, then the list will contain just one item ” in the form of a Finder reference. So the list will look something like this:
Your first script tries to set the label index of the list, whereas you really want to set the label index of the file in it. A single-item list can be coerced to anything to which the item in that list can be coerced. So by coercing the selection to alias in your second script, you get an alias version of the single file in the selection. (This won’t work if more than one item is selected.) Since the Finder understands aliases as well as its own references, the second script works.
Another, possibly better way would be to get the item directly:
tell application "Finder"
set theSelection to selection
set myFile to item 1 of theSelection
set label index of myFile to 1
This is good when more than one item is (or may be) selected, as you can then work through the list, doing whatever’s necessary to the enclosed items.
PS. I see this is my 500th post to the BBS. I hope it’s helpful. :rolleyes:
Thanks, kai. I thought I might get a telegram from the Queen today, but apparently not…
Stop press: But wait! A message of appreciation from Ray! Even better!
The theorist, the year the first part was published, and, of course, “the equation”.
Apparently, if you go up in a fast lift, and observe a train going past with a man rolling a ball along the corridor, you’ll bend a light beam round your head and come down again several years younger than your twin. Fortunately I don’t have one, but I’ve warned my nieces to be careful…