Re: Getting iPhoto album ID with AppleScript
Re: Getting iPhoto album ID with AppleScript
- Subject: Re: Getting iPhoto album ID with AppleScript
- From: has <email@hidden>
- Date: Sat, 13 Oct 2007 15:40:11 +0100
Nikita Zhuk wrote:
I'm developing an application which communicates with iPhoto via
AppleScript. My application tracks some iPhoto albums by using their
numeric album IDs, which are read from the AlbumData.xml file
generated by iPhoto. A requirement of my application is to be able to
change names of iPhoto albums by using their numeric album IDs. Since
I don't see any way to say this directly in AppleScript (i.e. "set
name of album with id 123 to 'TheNewName")
Note that the AppleScript syntax for by-id specifiers is 'ELEMENTNAME
id VALUE', e.g.:
set name of album id 123 to "TheNewName"
However, I get some unexpected album IDs with iPhoto version 7.1 (347)
on Mac OS X 10.4.10. If I try to fetch the id of the 7th album, I get
the following results:
1.
tell application "iPhoto"
id of album 7
end tell
Result: 4.294967297E+9
If the 'album' class's 'id' property is meant to represent the
AlbumId, that is a bug and should be reported as such. If it's meant
to contain an arbitrary unique value solely for use in identifying
album elements by id, that's just shortsighted design and you should
put in a feature request asking for it to use the AlbumId, which is
more useful, instead. Which it actually is, only an iPhoto engineer
could tell you, so I suggest filing it as a bug report with an
explanation as to why it should use the AlbumId specifically.
2.
tell application "iPhoto"
id of album 7 as integer
end tell
Result: -2.147483648E+9
3.
tell application "iPhoto"
id of album 7 as unsigned integer
end tell
Result: 1
Despite what iPhoto's dictionary claims, it's actually returning an
SInt64, and I wouldn't trust either AppleScript or its built-in
coercion handlers to handle those reliably. It's impossible for AS to
correctly handle all 64-bit ints: its integer type is limited to 30-
bits and it uses 64-bit floats for anything else, so you can lose
anything from 0 to 12 bits of precision. (e.g. iTunes scripters have
long had this problem when using its 'persistent ID' property in
AppleScript; iTunes recently finally caved to AS's stupidity and
switched from SInt64s to AS-proof hex strings instead.) None of this
is a problem with other bridges such as appscript that handle 64-bit
ints correctly, btw.
The 7th album has album id of 1, according to AlbumData.xml. Could
someone explain why I get values seen in first two cases (0x100000001
and 0x80000000)? In some other test cases (which I cannot reproduce
with my current iPhoto library) I've got the same result as in the
first case also in the third case, where I cast the return value to
unsigned integer.
In the first case, see my initial comment. From a brief, non-
comprehensive test, it looks as if the 'id' property is returning the
AlbumId + 0x100000000, but there's no way to know if that'll always
be the case short of finding out from an Apple engineer exactly
what's going on internally. It may be that the bottom 32 bits will
always be the same as for the AlbumId, in which case you could just
apply a simple bit mask to get the desired value, or there may be
something more complex or less predictable going on.
In the second and third cases, any results you get are likely
meaningless, and as I say I just wouldn't trust AS here if I were
you. If you really want to futz about with iPhoto's 'id' property and
try to figure out exactly what it's up to, I suggest you get yourself
a copy of Python/Ruby/ObjC appscript and use that instead. Otherwise,
find some other way of identifying albums that doesn't rely on
AlbumId, or wait and see what Apple's response to your bug report is
and take things from there.
HTH
has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
_______________________________________________
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