Re: iPhoto returns a real number as a photo id
Re: iPhoto returns a real number as a photo id
- Subject: Re: iPhoto returns a real number as a photo id
- From: has <email@hidden>
- Date: Mon, 14 Jun 2010 23:00:15 +0100
Rob Lewis wrote:
> iPhoto's scripting dictionary says that the "id" property of a photo is an integer. Yet when you fetch it, it's returned as a real number. What is one supposed to do with that? Very odd IMO.
If iPhoto's 'id' property contains a 32-bit integer (which I think it is), you should be fine. AppleScript reals are 64-bit, which provides more than enough room to represent a 32-bit integer without loss of precision, and unless iPhoto is broken then there shouldn't be any problem when passing these reals back to it.
OTOH, if it's a 64-bit integer, which is perfectly fine and normal in [Obj-]C, it'll present a big problem in AppleScript since its integers are only 30-bit or 62-bit depending on architecture, so AS will automatically coerce these integers to 64-bit reals. iTunes made the same mistake a few years back with one of its unique id properties (I might've filed a bug report on it at the time; can't recall now), and it was changed to a hex string a couple releases later.
> Other Apple apps (e.g., Address Book) use 128-bit unique IDs, returned as a string of 32 hex digits, in the same format used by the "uuidgen" command line utility. These are guaranteed to be unique. I doubt that iPhoto makes any such guarantee, or at least I can't find any mention of it.
iPhoto's id properties should be guaranteed unique within process lifetime, although you shouldn't assume they will persist between launches. Even in apps that use 128-bit uuids as AppleScript object ids, you shouldn't really assume those ids will remain the same from run to run, as that's not a guarantee made by the Cocoa Scripting system. Though in practice it's probably safe to do so, as those uuids are no doubt being used within the app's persistent data store for precisely that purpose.
> Anyone have any insight on iPhoto's id's and how to handle them?
Use them to keep a reliable handle on objects within a single scripting session (which is what by-id references are for); don't assume they will apply to the same objects the next time iPhoto is launched.
Also, treat all id values as opaque data. Like I say, the only time that you actually need to worry about their representation is when a careless developer uses 64-bit integers as object ids without realising that AppleScript will wreck those numbers. And that's only so you can file a bug report explaining that they need to convert it to a safe format like a hex string instead.
HTH
has
--
Learn AppleScript, 3rd edition, Sanderson & Rosenthal:
http://apress.com/book/view/9781430223610
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden