Page 1 of 1

Run AppleScript on batch of files (not one by one)

PostPosted: Tue Apr 14, 2015 8:23 am
by Jono
I have this script to import selected Finder items (images) to the 10.10.3 Photos app

Code: Select all
tell application "Finder" to set imageList to selection as alias list

tell application "Photos"
   import imageList into container "TestAlbum"
end tell



If I use 'theFile' in Hazel it processes each image one by one (and shows the single last image in 'Last Import' instead of the whole batch of images that were imported).

Code: Select all
tell application "Photos"
   import theFile into container "TestAlbum"
end tell



I'd like to run it as a batch on the folder of images, so it shows them all in 'Last Import'.
What would be the best way to do this? (I'm not sure if the best way would be to alter the script, and/or use 'Run rules on folder contents'.)

Re: Run AppleScript on batch of files (not one by one)

PostPosted: Tue Apr 14, 2015 11:24 am
by Mr_Noodle
It might be better to have a rule match the folder containing the files and import the whole thing (or have the script pick out which ones it should import). You'd need to have Hazel monitor one level up for this to work.

Re: Run AppleScript on batch of files (not one by one)

PostPosted: Tue Apr 14, 2015 4:03 pm
by Jono
Thanks, I've tweaked it to do this.

Code: Select all
set imageFolder to (path to home folder as text) & "Dropbox:Camera Uploads"
set photoAlbum to "Imported Dropbox Photos"

tell application "Finder" to set imageList to files of folder imageFolder as alias list
tell application "Photos" to import imageList into container photoAlbum
tell application "Finder" to move the imageList to the trash
tell application "System Events" to set visible of process "Photos" to false