Can anyone tell me why the below script wont work?
I’m trying to drop a folder full of images into a folder which has this action tagged to it. If i was just to drop the images in i can make it work but i’ll eventually be dropping multiple folders in concurrently so need to be able to process them separately.
The dialogs seem to display the correct file locations etc but when my photoshop action commences its as if i’m running the action without opening an image…
Hope someone can help.
Regards,
Dan
on adding folder items to this_folder after receiving these_items
repeat with an_item in these_items
display dialog "test: " & an_item & "-" & these_items
--set these_images to {}
set these_images to list folder an_item
--set these_images t-o (items of an_item)
repeat with an_image in these_images
if an_image contains ".jpg" or ".gif" or ".eps" or ".psd" or ".CR2" or ".tiff" or ".tif" or ".jpeg" or ".bmp" then
set this_image to alias
set this_image to (an_item as text) & an_image
display dialog "test2: " & this_image
tell application "Adobe Photoshop CS2"
activate
open this_image
do action "Image Robot" from "Robot"
end tell
end if
end repeat
end repeat
end adding folder items to
if an_image contains ".jpg" or ".gif" or ".eps" or ".psd" or ".CR2" or ".tiff" or ".tif" or ".jpeg" or ".bmp" then
a simlilar logic error was posted the other day.
if an_image contains ".jpg" or an_image contains ".gif" or an_image contains ".eps" or an_image contains".psd" an_image contains or an_image contains ".CR2" or an_image contains".tiff" or an_image contains ".tif" or an_image contains ".jpeg" or an_image contains ".bmp" then
this is how it has to be done
also you will need to check if the item is a folder at the start of your loop, and if it is a folder you will have to recurse through the directories
Hmmm, thanks for the response but i think my logic on the filetype checking was fine. I have a couple of system files in there to check it and they aren’t getting picked up since i added the line.
However the recursive folder/file thing you mention, how does this work?
My actual script works if i take the inner folder stuff out i.e if i was to drop a selection of images straight into the folder with the action applied to it, they get processed fine. So its just the fact that my images are in another folder inside the actionfolder and perhaps something to do with my ‘this_image’ variable?
This should get you the files within folders with in folders etc…:
tell application "Finder"
set thefolder to every file of entire contents of (choose folder) as alias list
repeat with i in thefolder
tell application "Adobe Photoshop CS"
activate
open i
--do action "Image Robot" from "Robot"
close current document saving no
end tell
end repeat
end tell
you will need to add the folder action handler and also your bit for picking what extension the files have
Here’s my adaptation of pidge1’s and Kim’s scripts. Also, Kim is correct in the way you need to write the if statement with the conditionals. If you change this script to the way you have it written, only the first item in the if will open.
on adding folder items to k after receiving these_items
tell application "Finder"
set t to every file of entire contents of k as alias list
repeat with i in t
set x to name of i
if x contains ".eps" or x contains ".jpg" or x contains ".jpeg" then
tell application "Adobe Photoshop CS2"
open i
end tell
end if
end repeat
end tell
end adding folder items to
PreTech
About recursion,
Recursion is a handler that calls itself until there are no more folders within the folder that is the current focus. This script I wrote was a test to get every file within a folder and it’s sub folders whose modification dates. This script allows for several folders to be selected until you press the “N” button (for no, Y for yes). I just used “want” for the prompt for speed of typing. The script only picks only files modified as of midnight on the current date. Also, once you have chosen a folder, the “property” remembers the folder until you recompile the script.
property y : {}
set l to {}
set d to false
repeat until d
set x to display dialog "want" buttons {"Y", "N"}
if button returned of x is "Y" then
set t to choose folder
set l's end to t
else
set d to true
end if
end repeat
set tstD to (current date) - (time of (current date))
theR(t, tstD)
on theR(c, tstD)
tell application "Finder"
repeat with anItem in folder c
set b to anItem as alias
if class of anItem is folder then
my theR(b, tstD)
else
if modification date of b is greater than tstD then
set y's end to b
end if
end if
end repeat
end tell
end theR
tell application "Finder" to reveal y
Checking the kind of files may be done with a shorter code.
on adding folder items to k after receiving these_items
tell application "Finder"
set t to every file of entire contents of k as alias list
(* CAUTION, 'as alias list' assumes that the folder contains more than one file *)
repeat with i in t
if name extension of i is in {"eps", "jpg", "jpeg"} then
tell application "Adobe Photoshop CS2"
open i
end tell
end if
end repeat
end tell
end adding folder items to
Yvan KOENIG (from FRANCE vendredi 12 janvier 2007 13:38:14)