"id" Property of Finder disks?

Hello all,

Helping a colleague with a script…

He wants to mount a disk and change its name.

So we decided to obtain the disk’s id property so as not to confuse anything when the name changes.

the following code:


tell application "Finder" to get id of disk "grumpy"

Returns -101, the id of the disk, under LEOPARD.

and the code


tell application "Finder" to get properties of disk "grumpy"

Shows “id:-101” in the Results. This is under LEOPARD.

However, when I switch to Tiger, the code gives an error “unknown object type” for the word “id” and the “id” property is not listed in the properties of the disk.

Is this a known problem with the “id” property?

If so, is there a workaround for getting a unique reference to the disk so that we can change its name?

Thanks.

Model: Mac Pro/MBP
AppleScript: 2.0 and 1.9
Browser: Safari 3 Leopard
Operating System: Other

I don’t see an id property for in Finder. However, there is an id property in System Events which returns a list such as {-100, 2}.

Thank you Bruce. I would never have guessed it was in System Events.

I do not know why it is a list of two items, but the first item seems to be unique so we will use that.

Cheers

  1. Regarding discussion of “LEOPARD”, remember that you’re still under NDA.

  2. Tiger’s Finder only provides id properties on window classes and only allows the by-id reference form to be used with ‘window’ and ‘application file’ elements (the latter for non-standard purposes at that).

  3. Use aliases. Alias values keep track of filesystem objects even if they’re moved or renamed. To convert between aliases and Finder references:

tell application "Finder"
	set anAlias to finderRef as alias -- Finder reference to alias
	set finderRef to item anAlias -- alias to Finder reference
end tell

Got it. That should work very well. I somehow got sidetracked off into ids.


tell application "Finder"
	set theAlias to disk "Grumpy" as alias
	set name of theAlias to "Doc"
	folders of disk "Doc"
end tell

Gives the folders of the original disk, Grumpy.

Thanks!