Sorry if this is a really dumb question, but I’ve had some major problems with Lists in AppleScript.
tell application "Finder"
set titles to list
set paths to list
set descriptions to list
set database to list
set aplicativos to the name of every process as list
if aplicativos contains "iPhoto" then
tell application "iPhoto"
set selecaoAlbum to the name of the current album
set selecao to the selection as list
set maximo to count of selecao
repeat with i from 1 to maximo
set fotoAtual to item i of selecao
set caminho to the image path of fotoAtual
set titulo to the title of fotoAtual
set comentario to the comment of fotoAtual
set item i of paths to caminho
set item i of titles to titulo
set item i of descriptions to comentario
end repeat
end tell
set item 1 of database to titles
set item 2 of database to paths
set item 3 of database to descriptions
return database as list
else
display dialog "iPhoto is not open. Please open iPhoto, select your photos and try running this action again."
end if
end tell
What I’m trying to do here is have a List (Database) with 3 Lists inside it, something like:
Database { titles{…}, paths{…}, descriptions{…} }
I get an error on set item 1 of database to paths, it says I can’t set item 1 of {}.
I think that means I’m not “creating” the lists properly?
Also, is there any AppleScript structure that would act as Cocoa’s “NSDictionary”? I really need something as powerfull as that for my script, lists aren’t working very well
Thank you very much,
Model: Mac Mini 1.5Ghz 512 64 80
Browser: Safari 417.8
Operating System: Mac OS X (10.4)
That didn’t work either, says “can’t set end of paths to caminho”.
I just tried with set paths to { “” } as list, but when I run the loop, I get:
Can’t set item 2 of { “Users/nandodevx/Pictures/iPhoto Library/2005/01/03/IMAG0062.JPG” } to “Users/nandodevx/Pictures/iPhoto Library/2005/01/03/IMAG0066.JPG” . Sigh
set x to {}
repeat 3 times
set end of x to "something"
end repeat
get x --> {"something", "something", "something"}
set item 2 of x to "nothing"
--> {"something", "nothing", "something"}
set beginning of x to {"what", "thing?"}
--> {{"what", "thing?"}, "something", "nothing", "something"}
set the second item of the first item of x to "wing?"
--> {{"what", "wing?"}, "something", "nothing", "something"}
set x to the rest of x
--> {"something", "nothing", "something"}
set x to the items -1 thru -2 of x
--> {"nothing", "something"}
Reading the manual would help. e.g. The crusty-but-serviceable AppleScript Language Guide is installed with Developer Tools or available online. There’s various third-party books and tutorials available as well. If you’re previous programming knowledge, your best choice would be the newly published second edition of Matt Neuburg’s ‘AppleScript: The Definitive Guide’.
tell application "System Events" to set isiPhotoRunning to process "iPhoto" exists
if isiPhotoRunning then
tell application "iPhoto"
set selecao to selection
set hasSelectedPhotos to selecao is not {} and class of item 1 of selecao is photo
end tell
if hasSelectedPhotos then
set titles to {}
set paths to {}
set descriptions to {}
repeat with fotoRef in selecao
tell application "iPhoto"
set end of titles to title of fotoRef
set end of paths to image path of fotoRef
set end of descriptions to comment of fotoRef
end tell
end repeat
return {titles:titles, paths:paths, descriptions:descriptions}
else
display dialog "Select your photos in iPhoto and try running this action again."
end if
else
display dialog "iPhoto is not open. Please open iPhoto, select your photos and try running this action again."
end if
Not built-in, though you can roll your own associative list objects or use existing third-party solutions. It does have a built-in record type, which is roughly analogous to a C struct in usage and is probably sufficient for your needs here.
Wow, tahnk you very, very much for the replies. I did look at the Apple documents, but since I haven’t played much with AppleScript, I didn’t get too far. I really appreciate your hel. Thank you very much!
Specifically, the latest edition of the AppleScript definitive guide recommended before is available via this link. My personal favorite is Beginning Applescript.