Copy link to clipboard
Copied
Hi there. I am trying to figure out whit this script works with CS4 however using the same action and the exact same script with CS5 it no longer works. Help?
This is the script.
on adding folder items to thisFolder after receiving theseFiles
tell application "Finder"
-- move psd files to temp folder
repeat with thisFile in theseFiles
if name extension of thisFile is "psd" then
move thisFile to folder "temp" of thisFolder
end if
end repeat
set thePSDFiles to every file of folder "temp" of thisFolder as alias list
set saveFolder to (folder "save" of thisFolder) as text
end tell
tell application "Adobe Photoshop CS5"
launch
repeat with thisFile in thePSDFiles
open thisFile showing dialogs never
tell current document
do action "CROPFLATTEN" from "SYMPA" -- action and set name, case sensitive
save in (saveFolder & name) as PNG with copying
close saving no
end tell
end repeat
end tell
tell application "Finder"
-- move .psd files left in temp folder to save folder
move thePSDFiles to folder saveFolder
end tell
end adding folder items to
on adding folder items to thisFolder after receiving theseFiles
tell application "Finder"
-- Make sure sub folder exists
if not (exists folder "temp" of thisFolder) then
set tempFolder to make new folder at thisFolder ¬
with properties {name:"temp"}
else
set tempFolder to folder "temp" of thisFolder as alias
end if
-- Ditto here…
if not (exists folder "save" of thisFolder) then
set saveFolder to make new folder at thisFolder ¬
with properties {name:"save"}
else
set saveFolder to folder "save"
...Copy link to clipboard
Copied
This is a known problem and here is a workaround for your CS5 version. From my colleague Jon...
In CS5, the interpretation of "alias/file/folder" object was broken. We have to ask the user to change the object from alias/file/folder to text/string outside Photoshop, then cast the text/string as file/alias in PS.
If this user change a little bit of the script, it should work for him:
Change
set thePSDFiles to every file of folder "temp" of thisFolder as alias list
to
set myFolder to (path to folder "temp" of thisFolder) as string
set thePSDFiles to name of every file of folder "temp" of thisFolder
Change
open thisFile showing dialogs never
to
open alias (myFolder & thisFile) showing dialogs never
Change
save in (saveFolder & name) as PNG with copying
to
save in (saveFolder & thisFile) as PNG with copying
Change
move thePSDFiles to folder saveFolder
to
move (every file of folder "temp" of thisFolder) whose name extension is "psd" to folder saveFolder
This should work. But I haven't tried it myself. Might need some tweak.
Copy link to clipboard
Copied
I modified the script to this - as you suggested.
on adding folder items to thisFolder after receiving theseFiles
tell application "Finder"
-- move psd files to temp folder
repeat with thisFile in theseFiles
if name extension of thisFile is "psd" then
move thisFile to folder "temp" of thisFolder
end if
end repeat
set myFolder to (path to folder "temp" of thisFolder) as string
set thePSDFiles to name of every file of folder "temp" of thisFolder
set saveFolder to (folder "save" of thisFolder) as text
end tell
tell application "Adobe Photoshop CS5"
launch
repeat with thisFile in thePSDFiles
open alias (myFolder & thisFile) showing dialogs never
tell current document
do action "CROPFLATTEN" from "SYMPA" -- action and set name, case sensitive
save in (saveFolder & thisFile) as PNG with copying
close saving no
end tell
end repeat
end tell
tell application "Finder"
-- move .psd files left in temp folder to save folder
move ((every file of folder "temp" of thisFolder) whose name extension is "psd") to folder saveFolder
end tell
end adding folder items to
However it doesnt open the files within photoshop CS5. It will move the files from the main folder to the temp folder located within the main folder. Nothing further happens though.
Copy link to clipboard
Copied
on adding folder items to thisFolder after receiving theseFiles
tell application "Finder"
-- Make sure sub folder exists
if not (exists folder "temp" of thisFolder) then
set tempFolder to make new folder at thisFolder ¬
with properties {name:"temp"}
else
set tempFolder to folder "temp" of thisFolder as alias
end if
-- Ditto here…
if not (exists folder "save" of thisFolder) then
set saveFolder to make new folder at thisFolder ¬
with properties {name:"save"}
else
set saveFolder to folder "save" of thisFolder as alias
end if
-- move psd files to temp folder
repeat with thisFile in theseFiles
if name extension of thisFile is "psd" then
move thisFile to tempFolder
end if
end repeat
-- Get the file list
set thePSDFiles to every file of tempFolder as alias list
end tell
repeat with thisFile in thePSDFiles
-- Coerce each alias to string
set thisFile to thisFile as string
tell application "Adobe Photoshop CS5"
activate
open alias thisFile showing dialogs never
tell current document
if mode is not RGB then
change mode to RGB
end if
flatten
-- action and set name, case sensitive
--do action "CROPFLATTEN" from "SYMPA"
save in file ((saveFolder as string) & name) as PNG with copying
close saving no
end tell
end tell
end repeat
tell application "Finder"
-- move .psd files left in temp folder to save folder
move thePSDFiles to folder saveFolder
end tell
end adding folder items to
This works fine here although Im no great fan of FAS… I just comment out the action call as I don't have this available…
Copy link to clipboard
Copied
Thank you so much! All I had todo with this was uncomment the action portion and change CS4 to CS5.
Perfect. If you have paypal I'll gladly send you a tip!
sympa@me.com
Finished Script:
on adding folder items to thisFolder after receiving theseFiles
tell application "Finder"
-- Make sure sub folder exists
if not (exists folder "temp" of thisFolder) then
set tempFolder to make new folder at thisFolder ¬
with properties {name:"temp"}
else
set tempFolder to folder "temp" of thisFolder as alias
end if
-- Ditto here…
if not (exists folder "save" of thisFolder) then
set saveFolder to make new folder at thisFolder ¬
with properties {name:"save"}
else
set saveFolder to folder "save" of thisFolder as alias
end if
-- move psd files to temp folder
repeat with thisFile in theseFiles
if name extension of thisFile is "psd" then
move thisFile to tempFolder
end if
end repeat
-- Get the file list
set thePSDFiles to every file of tempFolder as alias list
end tell
repeat with thisFile in thePSDFiles
-- Coerce each alias to string
set thisFile to thisFile as string
tell application "Adobe Photoshop CS5"
activate
open alias thisFile showing dialogs never
tell current document
if mode is not RGB then
change mode to RGB
end if
flatten
-- action and set name, case sensitive
do action "CROPFLATTEN" from "SYMPA"
save in file ((saveFolder as string) & name) as PNG with copying
close saving no
end tell
end tell
end repeat
tell application "Finder"
-- move .psd files left in temp folder to save folder
move thePSDFiles to folder saveFolder
end tell
end adding folder items to
Copy link to clipboard
Copied
I have one more question. Is there any way to conver this script to a stay open application that will check the last modified date of the main folder "Folder2" ?
I found this script wich illustrates the principle but I cant get it to work.
In short.. could anyone conbine these two scripts?
property targetPath : "sneJ:Shared Folders:Jens Public:Drop Box:" -- path to target folder
property targetFolder : 0 -- target folder alias (set at startup)
property modDate : 0 -- mod date of folder when last checked
on run
set targetFolder to alias targetPath -- get alias to the folder
end run
on idle
set newModDate to modification date of (info for targetFolder)
if modDate = 0 or newModDate > modDate then
set modDate to newModDate
folderChanged(targetFolder)
end if
return 3 -- Idle time in seconds
end idle
on folderChanged(f)
beep
-- Put anything you want here, and it'll run whenever the
-- folder is modified. See the “What's New?” sample script
-- for a more sophisticated example, which figures out what
-- files have been added and displays their names to the
-- user.
end folderChanged
on adding folder items to thisFolder after receiving theseFiles
tell application "Finder"
-- Make sure sub folder exists
if not (exists folder "temp" of thisFolder) then
set tempFolder to make new folder at thisFolder ¬
with properties {name:"temp"}
else
set tempFolder to folder "temp" of thisFolder as alias
end if
-- Ditto here…
if not (exists folder "save" of thisFolder) then
set saveFolder to make new folder at thisFolder ¬
with properties {name:"save"}
else
set saveFolder to folder "save" of thisFolder as alias
end if
-- move psd files to temp folder
repeat with thisFile in theseFiles
if name extension of thisFile is "psd" then
move thisFile to tempFolder
end if
end repeat
-- Get the file list
set thePSDFiles to every file of tempFolder as alias list
end tell
repeat with thisFile in thePSDFiles
-- Coerce each alias to string
set thisFile to thisFile as string
tell application "Adobe Photoshop CS5"
activate
open alias thisFile showing dialogs never
tell current document
if mode is not RGB then
change mode to RGB
end if
flatten
-- action and set name, case sensitive
do action "CROPFLATTEN" from "SYMPA"
save in file ((saveFolder as string) & name) as PNG with copying
close saving no
end tell
end tell
end repeat
tell application "Finder"
-- move .psd files left in temp folder to save folder
move thePSDFiles to folder saveFolder
end tell
tell application "Finder"
set finalFolder to folder "Untitled:Users:sympa:Desktop:finalfolder"
set initialFolder to folder "Untitled:Users:sympa:Desktop:Folder2:save"
move everyFile of initialFolder to finalFolder
set label index of everyFile of finalFolder to 5
end tell
end adding folder items to
Copy link to clipboard
Copied
Funny… thats other thing you can do with AppleScript that Im no great user or fan of… Stay open apps… What is much nicer is adding your scripts to iCal event alarms. Its very flexible, a piece of cake to set up… Nothing need be running either…
Copy link to clipboard
Copied
Alright, If I wanted to attach this to an ical event alarm how would I do that and how would that benefit me more? What im trying todo is make sure no files get "missed". I need every file within the drop folder to get processed even if two users are dropping items simultaneously.
Copy link to clipboard
Copied
The reason Im no fan of these is they tend to be a little erratic at times… (been called that myself) When testing the script I posted there can be a lag in response to the items added event some times it no trigger at all. The problem being there is little or nothing you can do when this is the case… Personally I always find these scripts the most difficult to get right. You do have several options available to you but knowing a little more about the work flow would be of help… iCal can run AppleScripts that are added to calendar events. I've also had it run ESTK scripts too although I have not checked now that CS5 appears a little fussier over it's script locations… Bridge scripting has a 'schedule tasks' but it requires it be running. iCal can do the same need not be running.
Copy link to clipboard
Copied
Alright Mark. Youve been super hepful so far so I have one last question. This is being run on a separate computer as a server. Occaisionally when a user has dropped files a file will be corrupt and photoshop cannot open the file. When this occurs the entire script hangs and waits for input. It requires me to keep checking on the computer and forcing photoshop to continue. Is there a way I can force photoshop to skip this corrupted file if it throws an error?
I saw another post of yours here using the method below. However I cant seem to get the try block to play well with photoshop when I tried to combine it and my current script. Whenever I used the try block, the script would skip photoshop altogether and simply begin moving the file. Help please!
try
with timeout of 2 seconds
open The_File
end timeout
on error
tell application "System Events"
tell application process "Adobe Photoshop CS2"
keystroke return
end tell
end tell
end try
property lastModDate : 0 -- mod date of folder when last checked
global targetFolder, saveFolder
on run
-- set targetFolder as an alias on first run
set targetFolder to alias "ACTION:Users:Shared:Hotfolder"
-- create the save folder if it doesn't exist; store its path as text
tell application "Finder"
if not (exists folder "save" of targetFolder) then
make new folder at thisFolder with properties {name:"save"}
end if
set saveFolder to folder "save" of targetFolder as text
end tell
end run
on idle
-- 'info for' is deprecated, so getting mod date from the Finder
tell application "Finder"
set currentModDate to modification date of targetFolder
end tell
if lastModDate = 0 or currentModDate > lastModDate then
set lastModDate to currentModDate
ProcessNewItems()
end if
return 120 -- Idle time in seconds
end idle
on ProcessNewItems()
with timeout of (30 * 60) seconds —30 min timeout
tell application "Finder"
-- move psd files to save folder, go back to idle if there are none to process
set thePSDFiles to move ¬
(every file of targetFolder whose name extension is "psd") ¬
to folder saveFolder
if thePSDFiles = {} then return
end tell
repeat with thisFile in thePSDFiles
-- Coerce each alias to string. files are in Finder file specs, so use the Finder
tell application "Finder"
set thisFile to thisFile as text
end tell
tell application "Adobe Photoshop CS5"
activate
set display dialogs to never
end tell
tell application "Adobe Photoshop CS5"
activate
open alias thisFile showing dialogs never
tell current document
if mode is not RGB then
change mode to RGB
end if
flatten
-- action and set name, case sensitive
-- do action "CROPFLATTEN" from "SYMPA"
save in file (saveFolder & name) as PNG with copying
close saving no
end tell
end tell
end repeat
tell application "Finder"
set finalFolder to folder "ACTION:Volumes:photobasearchive:hotfolder:finals"
move every file of folder saveFolder to finalFolder
delete every file of folder saveFolder
end tell
end timeout
end ProcessNewItems
Copy link to clipboard
Copied
Im currently at work and have no access to my snippets… But the example posted in this forum does work. What you need is a 'try/on error' inside of a short time out statement… Say 10 seconds dependent on your images and how long you expect to take to open… Photoshop will not error in these situations but AppleScript will from the timeout… in the on error call a sub-routine to do the keystroke. That should be it. It looks like we may get a change in this behavior in future releases Tom has requested it… I can't do any of this using the ESTK…
Copy link to clipboard
Copied
Is this the correct code then?
property lastModDate : 0 -- mod date of folder when last checked
global targetFolder, saveFolder
on run
-- set targetFolder as an alias on first run
set targetFolder to alias "ACTION:Users:Shared:GAP_PNG:process"
-- create the save folder if it doesn't exist; store its path as text
tell application "Finder"
if not (exists folder "save" of targetFolder) then
make new folder at thisFolder with properties {name:"save"}
end if
set saveFolder to folder "save" of targetFolder as text
end tell
end run
on idle
-- 'info for' is deprecated, so getting mod date from the Finder
tell application "Finder"
set currentModDate to modification date of targetFolder
end tell
if lastModDate = 0 or currentModDate > lastModDate then
set lastModDate to currentModDate
ProcessNewItems()
end if
return 60 -- Idle time in seconds
end idle
on ProcessNewItems()
with timeout of (30 * 120) seconds
tell application "Finder"
-- move psd files to save folder, go back to idle if there are none to process
set thePSDFiles to move ¬
(every file of targetFolder whose name extension is "psd") ¬
to folder saveFolder with replacing
if thePSDFiles = {} then return
end tell
repeat with thisFile in thePSDFiles
-- Coerce each alias to string. files are in Finder file specs, so use the Finder
tell application "Finder"
set thisFile to thisFile as text
end tell
tell application "Adobe Photoshop CS5"
activate
try
with timeout of 2 seconds
open alias thisFile showing dialogs never
end timeout
on error
tell application "System Events"
tell application process "Adobe Photoshop CS5"
keystroke return
end tell
end tell
end try
tell current document
if mode is not RGB then
change mode to RGB
end if
if exists path item "crop" then -- check if there is a path called crop, if so do action, else flatten and save
flatten
-- action and set name, case sensitive
do action "CROPFLATTEN" from "SYMPA"
save in file (saveFolder & name) as PNG with copying
close saving no
else
flatten
save in file (saveFolder & name) as PNG with copying
close saving no
end if
end tell
end tell
end repeat
tell application "Finder"
set temps to folder "ACTION:Volumes:photobasearchive:hotfolder:_temps"
if not (exists folder "ACTION:Volumes:photobasearchive:hotfolder:_temps:GAP_PNG") then
make new folder at temps with properties {name:GAP_PNG}
else
set finalFolder to folder "ACTION:Volumes:photobasearchive:hotfolder:_temps:GAP_PNG"
delete
move every file of folder saveFolder to finalFolder with replacing
delete every file of folder saveFolder
end if
-- set the label index of every file of folder finalFolder to 7 -- grey
end tell
end timeout
end ProcessNewItems
Copy link to clipboard
Copied
HI.
I can't "AppleScript"... but get a feeling that this has something to do with the issue I came across:
In earlier versions of photoshop (e.g.CS3) in OSX I was able to move a PSD file that was still to a new folder and the path of the file would update automatically in PS without me having to close the file. I could see the new path by cmd+clicking the title bar. This is one of the most beautiful things in OSX, I think, and it works in most programs. It allows me to re-organize files on the fly and still continue working with them. Very efficient.
But I just noticed now -- first serious job with the new CS5.5 in my new iMac -- that this no longer works in Photoshop. Now if I want to move a file I have to close it, move it and reopen.
Is there a workaround for this issue? Or maybe my issue has nothing to do with this post?