I’ve got a workflow I need to whip up pretty pronto (i.e. 24 hours), and I’ve hit some snags. First, let me explain what I would like to happen, as a folder action.
image files dropped into folder
images filtered by image size (pixels)*
images above a certain pixel width get moved into a new folder named OK contained in the original folder
images below a certain pixel width get attached to a new email and sent
The problem seems to be that the filtering by pixel size is not working. It doesn’t matter what I put in for criteria, all files pass through. Of course I know that these custom actions are supported by the creator only, but I thought I’d ask here to see if anyone else has had this issue. I also think that this would be possible to do via applescript, but my knowledge of Applescript is about 0.5% of all you can know about it.
I am doing steps three and four by having two workflows attached to the same folder. Workflow A runs, which sorts out the “OK” files, and workflow B starts with a 10 second pause - to allow workflow A to finish - before it emails the “bad” files.
I am curious about variables because I think I can use them to streamline some aspects of the workflow, such as the emailing part. If I can grab the name of the root folder, which would be an email address, I can use that folder name as the email address for the new email.
If anyone has any pointers whatsoever, be it via Automator or (I’m afraid…) Applescript, I would absolutely love to hear them.
I am still a novice at Automator, but I can do AppleScript pretty well. I was able to whip up a small script that can be included in an Automator action that will successfully filter images by pixel size. The main issue is that the output of that action is a list of files that meet the criteria, while all other files are ignored.
From what I can tell, this is still the major drawback to Automator; it is not designed to make any decisions. It is very good in processing files quickly and efficiently, but if you want 1 of two (or more) outcomes, you need to use AppleScript.
What we could easily do, however, is to create two workflows, one that selects the “good” images and the other selects the “bad.” Not terribly efficient, but certainly functional and clean.
Anyway, here is the AppleScript for filtering images based on pixel dimensions (I set the minimum dimensions to 6 megapixels):
on run {input, parameters}
set final_list to {}
repeat with ea_ch in input
tell application "Image Events"
close images
set b to open (ea_ch as alias)
set c to dimensions of b
close b
end tell
if ((c's item 1) * (c's item 2)) > 6000000 then set end of final_list to (ea_ch as text)
end repeat
return final_list
end run
The output is a list of files:
TyrannoDrive:Users:praxisii:Pictures:7February2007Prints.fpbf:4x6207:4x62071.JPG
TyrannoDrive:Users:praxisii:Pictures:7February2007Prints.fpbf:4x6207:4x620710.JPG
TyrannoDrive:Users:praxisii:Pictures:7February2007Prints.fpbf:4x6207:4x620711.JPG
Etc.
So, give this a whirl, and come back if you need any more help.
I think this is the big thing holding Automator back as well - no way to do an if-then-else type statement.
This is fine - I was using two workflows originally anyway.
Excellent! This looks like it either is or is very close to what I wish to do. I’m only working with small files - logos for print output - so 6 megapixels is mighty high for my needs. If I were to change it for, say, 450x450ish pixels, i’d change the 6000000 in your script to 200000 or so, right? And then to use the script to filter out low-res images, change the > before the 6000000 to a <, correct?
Your method using Applescript is more elegant than what is available using the Automator actions for Photoshop, for filtering based on megapixels ignores image orientation. In the Automator CS3 actions, you have to specify both horizontal and vertical pixel measurements.
Thanks very much for your help! I will try your script right now and see if it works with the tweaks I need to make and let you know. If anything, this makes a nice intro for me to Applescript, which I definitely want to learn.
My AS simply multiplies the height and width in pixels, so 450x450 would be 202500.
We actually have a set of AS introductory tutorials right here at MacScripter. My particular set contains 12 lessons, and there are more there for the reading. Most are around 2 years old, so be sure sure to read all the comments at the end of the articles for updates and other issues that have changed since their original publications.
Probably comes down to what action you are using to feed the Run AppleScript action. In my test workflow, I used Get Specified Finder Items to select a specific folder full of various sized images. The next action is then Get Folder Contents, which feeds each file into the Run AppleScript action.
It may be choking on a file that it encounters that is not a valid image file (my folder contains only JPG files, but Image Events can read pretty much any image file). If that is the case, this fix should work:
on run {input, parameters}
set final_list to {}
repeat with ea_ch in input
try
tell application "Image Events"
close images
set b to open (ea_ch as alias)
set c to dimensions of b
close b
end tell
if ((c's item 1) * (c's item 2)) > 6000000 then set end of final_list to (ea_ch as text)
end try
end repeat
return final_list
end run
By using the try and end try statements, we can skip any files that the script cannot read. Give that a shot and see. If there are still problems, either post your list of workflow actions, or email me the workflow itself.