Re: Getting iPhoto album ID with AppleScript
Re: Getting iPhoto album ID with AppleScript
- Subject: Re: Getting iPhoto album ID with AppleScript
- From: Bill Cheeseman <email@hidden>
- Date: Sat, 13 Oct 2007 07:57:51 -0400
- Thread-topic: Getting iPhoto album ID with AppleScript
on 2007-10-13 7:19 AM, Nikita Zhuk at email@hidden wrote:
> 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"), I use a loop where I loop
> through all iPhoto albums, check whether album's ID is the same
> integer as my id and set name of the found album.
The id you see in your first example is in fact an integer, but AppleScript
displays it in "scientific" notation because it's too long for AppleScript
to display otherwise. To see what I mean, type this script into Script
Editor and hit the Compile button:
tell application "iPhoto"
4294969906
end tell
When you hit the Compile button, Script Editor coverts it to this:
tell application "iPhoto"
4.294969906E+9
end tell
If you ask iPhoto for the class of the result, it will say 'real':
tell application "iPhoto"
4.294969906E+9
class of result
end tell
But that's a lie, for your purposes. It is in fact an integer without a
fractional part.
I have a suggestion: Just use the ids that iPhoto gives you, and don't
coerce them to another type ("coerce" is the AppleScript term for "cast").
The iPhoto dictionary says the id is of type 'integer', and for your
purposes it is.
The correct way to refer to an album by its id is 'album id xxx'. You don't
have to loop through all of the albums looking for a match. For example,
this works:
name of album id (id of album 8)
Which is equivalent to this, which also works:
set myID to id of album 8
name of album id myID
Whether this will work with the ids you get from the xml file, I don't know.
But I expect not, since an AppleScript object's id is always supposed to be
unique within the running program. When you open an album from disk, it may
be assigned a unique id at that moment (this is the way most applications
work), and it probably has nothing to do with any id saved to disk. If it
used an id from disk, there might be a risk that you could open two albums
from different computers with the same id.
I'm not entirely sure of this, however, because iPhoto could assign a uuid
(universally unique identifier) to every new album you create, and then the
ids on disk would be unique throughout the world for the next several
thousand years. I suppose iPhoto might do that, but I don't think so because
uuids aren't integers.
In your program, do you open the album on disk in iPhoto? If so, get its id
within iPhoto, not from disk, after you open it. Then you can use the its id
within your program as shown above.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
www.quecheesoftware.com
PreFab Software - www.prefabsoftware.com
_______________________________________________
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