PDA

View Full Version : Aperture Applescript




Sunsplitter
Jun 8, 2012, 06:21 PM
I'm new to coding and to Applescript but I managed to cobble together a script for Aperture to copy all the Custom Metadata fields for selected images into Keywords for those images. It works but it runs kind of slowly, and I'm guessing it's because I messed up the repeat function somehow and it's performing the same action multiple times. Could someone with better coding knowledge than I take a look and let me know if there's a fix for this?

on run
tell application "Aperture"
set theSel to the selection
repeat with i from 1 to number of items in theSel
set tImg to item i of theSel
repeat with tImg in theSel
set theOut to ""

repeat with curTag in custom tags of tImg
set tagVal to value of curTag
set theOut to theOut & tagVal & "," & return
set tKey to theOut
try
tell tImg
make IPTC tag with properties {name:"Keywords", value:tKey}
end tell
end try
end repeat

end repeat
end repeat
end tell
end run



kryten2
Jun 8, 2012, 07:42 PM
The first repeat loop goes through every item in your selection. The second repeat loop does the same thing. Remove or comment out the second repeat loop and see if the script does what it needs to do. Repeat loops are notorious for slowing down scripts.

Sunsplitter
Jun 8, 2012, 08:39 PM
The first repeat loop goes through every item in your selection. The second repeat loop does the same thing. Remove or comment out the second repeat loop and see if the script does what it needs to do. Repeat loops are notorious for slowing down scripts.

Ah yeah, that seems to be it. It's going a lot quicker now; thanks for your help.