Skip to main content
April 22, 2011
Answered

Photoshop CS5 Applescript

  • April 22, 2011
  • 1 reply
  • 5316 views

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

This topic has been closed for replies.
Correct answer Muppet_Mark-QAl63s

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…

1 reply

Tom Ruark
Inspiring
April 22, 2011

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.

April 24, 2011

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.

Muppet_Mark-QAl63s
Muppet_Mark-QAl63sCorrect answer
Inspiring
April 25, 2011

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…