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

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

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'.)
Jono
 
Posts: 26
Joined: Wed May 09, 2012 5:52 am
Location: UK

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.
Mr_Noodle
Site Admin
 
Posts: 11867
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

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
Jono
 
Posts: 26
Joined: Wed May 09, 2012 5:52 am
Location: UK


Return to Support