Hi, I’m new to both Applescript and this forum, so if I’m describing things incorrectly, and/or have this in the wrong place, please just let me know and I’ll happily change as needed.
I did try searching the forum first to see if I could find what I needed, but didn’t come up with anything I could then use, which is likely more down to my lack of experience than anything else - apologies if I missed the obvious!
I’ve written a script embedded within Automator, so wasn’t sure whether to post under automator, or here, but chose here as it’s more a script than an automator action. I’m really only using Automator to put some dialogue on the front and back of what’s essentially a script. This is because as far as I can see, Automator (at least under Mac OS X 10.6.8, which I’m using) doesn’t allow selection of both source and destination files to carry out an action - if I’m wrong on that, please correct me, as that would probably be easier for me to set up.
The script I’ve written is as follows -
on run {input, parameters}
set exftarg1 to " -tagsfromfile "
set exftarg2 to " '-IPTC:Keywords<IPTC:Keywords' '-XMP-dc:Subject<IPTC:Keywords' "
set s to quoted form of POSIX path of (choose file with prompt "CHOOSE SOURCE FILE" without invisibles)
set d to quoted form of POSIX path of (choose file with prompt "CHOOSE FILES TO CHANGE" with multiple selections allowed)
do shell script "exiftool" & exftarg1 & s & exftarg2 & d
return input
end run
And it seems to work - almost! The problem I’m having is that I can use my script to edit one destination file, but cannot edit multiple destination files even though I have
on the d (destination) choice.
I’m using exiftool to edit the metadata of various images, so the script is built around that.
First I’m setting 2 variables with the contents of argument files to go into exiftool so it can process the commands.
Then I set “s” to allow me to select a source file in Finder from which to obtain the image metadata I want.
Then I set “d” to allow me to select the destination files in Finder into which I want to write that image metadata.
Then I execute exiftool via a shell script.
Note that exiftool is capable of handling multiple files passed to it, and I’ve tested that both on the Terminal command line directly and in various Automator apps (via “for f in “$@”’ combined with '”$f"') , so feel reasonably confident it’s not exiftool that’s causing the problem.
Assuming it’s not exiftool, when running the workflow in Automator everything works until it gets to this line -
set d to quoted form of POSIX path of (choose file with prompt "CHOOSE FILES TO CHANGE" with multiple selections allowed)
If I select just one file to write metadata to, it works, executing exiftool to correctly put the metadata into the image tags I specified in exftarg2.
If I select more than one image at that point, which it allows, the following error is returned -
and does not execute the exiftool command, so no files are changed. As it’s a syntax error, I’m thinking the problem is with Applescript rather than exiftool.
It seems I’m missing something, as even though I think that with multiple selections allowed it should work for multiple files, it doesn’t, and when it returns the error, the path it shows is correct, even though it states it can’t get it.
I’ve now spent hours trying variations of this and getting no further, so if anyone can enlighten me on my mistakes, and provide examples of what I should do to correct it, I’d be very grateful.
Thanks,
Adrian
Model: Macbook Air model 3,2
AppleScript: 2.3
Browser: Safari 5.1.10 (6534.59.10)
Operating System: Mac OS X (10.6)