Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Get current file of Photoshop.

All I want to do is from with in photoshop (the user applescript folder) is run this script but rather than select a file, use the open file on photoshop and process (there maybe others open so it would need to get the current document and file name)


Many Thanks


Matt



property type_list : {"8BPS"}

property extension_list : {"psd"}

script o

property theseNames : {}

end script



set thefile to (choose file) as text--> the file path



tell application "Finder" to set TheName to (name of file thefile) --> the name

set the1stLetter to the first character of TheName --> the first letter

set the2ndLetter to the second character of TheName --> the first letter

set brandInitial to {the1stLetter, the2ndLetter} as text


if brandInitial is equal to "BH" then ¬

set brandName to "BRAND"

if brandInitial is equal to "AL" then ¬

set brandName to "BRand"







set weekNumber to ""


display dialog "Please enter the week number:" default answer weekNumber

set weekNumber to text returned of result

try

if weekNumber = "" then error

set theWeekNumber to theWeekNumber as number


on error

set thePrefix to "INVALID ENTRY! "

end try


--Folder location Setup


set this_local_folder to "Images:2012-2013"

set localWeekFolder to my getFolderPath("WK" & weekNumber, this_local_folder)

set localBrandFolder to my getFolderPath(brandName, localWeekFolder)

set localBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", localBrandFolder)

set localBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_HR", localBrandFolder)

set localBrandFolder_PSD to my getFolderPath(brandName & "_WK" & weekNumber & "_PSD", localBrandFolder)


set this_Network_folder to "DCKGEN:Brands:Zoom:Brand - Zoom:Upload Photos:2013:"

set networkWeekFolder to my getFolderPath("Week" & weekNumber, this_Network_folder)

set networkBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", networkWeekFolder)


--all files for website

set website_images to "DCKGEN:Website_Images:"


--set up names to destination folders and create over Network for FTP collection (based on a mounted drive)

set this_ftp_folder to "Impulse:"

set ftpWeekFolder to my getFolderPath("Week" & weekNumber, this_ftp_folder)

set ftpBrandFolder to my getFolderPath(brandName, ftpWeekFolder)

set ftpBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", ftpBrandFolder)

set ftpBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_HR", ftpBrandFolder)


--set theFolder to eachItem as string -- I think this is the line that could be causing the problem.


--taking the folder identify which process it must follow.

if brandName is equal to "BRAND" then



tell application "Adobe Photoshop CS5.1"


-- I remove the command activate, Photoshop stay in background

set ruler units of settings to pixel units


try


open (aliasthefile) showing dialogsnever

set origName to name of current document

set myOptions to {class:JPEG save options, quality:12}

set myPSDOptions to {class:Photoshop save options, embed color profile:true, save layers:true}


tell current document




--If the quick mask mode has been left on then delete the channel Quick Mask

if (quick mask mode) then delete channel ¬

"Quick Mask"


--If the Layer is incorrectly labeled with Original Layer it needs renaming to original Image

if (exists layer "Original Layer") then ¬

tell layer "Original Layer" to set name to "Original Image"


savein (localBrandFolder_PSD & origName) asPhotoshop formatwith optionsmyPSDOptions without copying

(delete layer "Original Image") flatten



resize imageresolution 300 resample methodnone



--sharpen image


filtercurrent layerusingunsharp maskwith options {amount:80, radius:3.2, threshold:0}



savein (localBrandFolder_High_Res & name) asJPEGwith optionsmyOptions without copying



--get file path, return path of the JPEG file, work with (without copying)


-- (with copying) : it return path of PSD file

set newFile to file path--( return path of type alias )



-- duplicate file using the Finder -->on duplicateFile(..)

my duplicateFile(newFile, {ftpBrandFolder_High_Res})



--Prepare for Low RES by resetting image history

set current history state to history state 3



flatten



resize imagewidth 1348


resize imageresolution 300 resample methodnone


filtercurrent layerusingunsharp maskwith options {amount:80, radius:3.2, threshold:0}



--add save to lowResFolder with same options


savein (localBrandFolder_Low_Res & name) asJPEGwith optionsmyOptions without copying


set newFile to file path

set newFile2 to newFile as string-- for testing end of name

if newFile2 ends with "_2.jpg" or newFile2 ends with "_3.jpg" then -- exclude website_images

my duplicateFile(newFile, {networkBrandFolder_Low_Res, ftpBrandFolder_Low_Res})

else

my duplicateFile(newFile, {networkBrandFolder_Low_Res, ftpBrandFolder_Low_Res, website_images})

end if



closesavingno

end tell

end try


end tell




--End BH

end if

--then the next etc.









on duplicateFile(tFile, foldersPath) -- tFile is an alias, foldersPath is a list of folder

tell application "Finder" to repeat with folderPath in foldersPath

with timeout of 200 seconds-- adjust it, error if the copy is longer that 200 seconds


duplicatetFiletofolderfolderPath with replacing

end timeout

end repeat

end duplicateFile



on getFolderPath(tName, folderPath)

tell application "Finder" to tell folder folderPath

if not (exists folder tName) then

return (makenewfolderat it with properties {name:tName}) as string

else

return (folder tName) as string

end if

end tell

end getFolderPath

iMac, Mac OS X (10.6.8)

Posted on Nov 1, 2012 3:53 AM

Reply
11 replies

Nov 5, 2012 6:49 AM in response to MattJayC

I've tried this, but get the error


error "Finder got an error: Can’t get file \"TM15RI01268MU4MM.psd\"." number -1728 from file "TM15RI01268MU4MM.psd"



tell application "Adobe Photoshop CS5.1"

set DocumentName to name of front document as string

if DocumentName contains ".psd" then

set aCount to count every character of DocumentName

set aCount to aCount - 4

set DocumentName to characters 1 thru aCount of DocumentName as string

set DocumentName to word -1 of DocumentName as string

end if


display dialogDocumentName

end tell



set thefile to DocumentName

Nov 6, 2012 8:15 PM in response to MattJayC

Hi,



The beginning of the script according to your first post will be like this.

--------

-- remove this line -- set thefile to (choose file) as text --> the file path

tell application "Adobe Photoshop CS2" --CS5.1"

settheDoctocurrent document

set thefile to (file path of theDoc) as text --> the file path

endtell

----------


The rest of the script is the same, except you must replace all 'current document' by thedoc

Nov 22, 2012 6:31 AM in response to Jacques Rioux

Sorry only just getting the time to try this, it seams to be running better but not saving


I get the error

I changed all the current doc bits over too?



Hope you can help


get file path of document "TM15BW00792GY5GM.psd"

--> error number -1728 from document "TM15BW00792GY5GM.psd"

end tell

tell application "AppleScript Editor"

open end


--> missing value

end tell

Result:

missing value

Nov 22, 2012 8:50 AM in response to MattJayC

MattJayC wrote:


I get the error

get file path of document "TM15BW00792GY5GM.psd"

--> error number -1728 from document "TM15BW00792GY5GM.psd"


It's a bug on CS5 http://forums.adobe.com/message/2818628


This solution work, but not tested on CS5 (I don't have that version).

The beginning of the script

----------------

tell application "Adobe Photoshop CS5.1"

setthefileto (file pathofcurrent document) astext --> get the file path

endtell

----------------


Add this handler to the end of the script.

----------------

ongetDocByPath(tFile)

set f to tFile as alias

tell application "Adobe Photoshop CS5.1"

repeat with i in (get documents)

if file path of i is f then return contents of i --return the doc

end repeat

end tell

endgetDocByPath

----------------


Replace all 'current document' in rest of your script by (mygetDocByPath(tFile))




Others solutions on Adobe Forum:

1- Run Photoshop in 32 bits mode

2- Replace the "ScriptingSupport.plugin" file, look at message #47 in this thread http://forums.adobe.com/message/2883957

Nov 23, 2012 12:53 AM in response to Jacques Rioux

Sadly still no joy, I assume in my script that this part is wrong

open (aliasthefile) showing dialogsnever


However even with this removed it doesn't work.

Also tried replacing thedoc with thefile.



either way this error again


tell application "Adobe Photoshop CS5.1"


set ruler units of settings to pixel units

open alias "Hal 9000:Users:matthew:Desktop:BH_WK13_PSD:BH70ER05212CR1RH.psd" showing dialogs never


--> current application

end tell

tell application "AppleScript Editor"

open end


--> missing value

end tell

Result:

missing value



Could saving the file in a temp folder and then reopening work? and delete ince the script has run? As you know from previous scripts it works but just not from "current document"?


Nonetheless thanks for all you help.

Nov 23, 2012 1:44 AM in response to MattJayC

Ok, there is improvement, the script gets the path without error.



Test this script in the editor., don't use your script.

-----------

tell application "Adobe Photoshop CS5.1"
      set thefile to (file path of current document) --> get the file path (an alias)
end tell
set thefile to thefile as string

tell application "Finder" to set TheName to (name of file thefile) --> the name
set the1stLetter to the first character of TheName --> the first letter
set the2ndLetter to the second character of TheName --> the first letter
set brandInitial to {the1stLetter, the2ndLetter} as text

if brandInitial is equal to "BH" then ¬
      set brandName to "BRAND"
if brandInitial is equal to "AL" then ¬
      set brandName to "BRand"

set weekNumber to ""

display dialog "Please enter the week number:" default answer weekNumber
set weekNumber to text returned of result
try
      if weekNumber = "" then error
      set theWeekNumber to theWeekNumber as number

on error
      set thePrefix to "INVALID ENTRY! "
end try

--Folder location Setup
set this_local_folder to "Images:2012-2013"
set localWeekFolder to my getFolderPath("WK" & weekNumber, this_local_folder)
set localBrandFolder to my getFolderPath(brandName, localWeekFolder)
set localBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", localBrandFolder)
set localBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_HR", localBrandFolder)
set localBrandFolder_PSD to my getFolderPath(brandName & "_WK" & weekNumber & "_PSD", localBrandFolder)

set this_Network_folder to "DCKGEN:Brands:Zoom:Brand - Zoom:Upload Photos:2013:"
set networkWeekFolder to my getFolderPath("Week" & weekNumber, this_Network_folder)
set networkBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", networkWeekFolder)

--all files for website
set website_images to "DCKGEN:Website_Images:"

--set up names to destination folders and create over Network for FTP collection (based on a mounted drive)
set this_ftp_folder to "Impulse:"
set ftpWeekFolder to my getFolderPath("Week" & weekNumber, this_ftp_folder)
set ftpBrandFolder to my getFolderPath(brandName, ftpWeekFolder)
set ftpBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", ftpBrandFolder)
set ftpBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_HR", ftpBrandFolder)

--set theFolder to eachItem as string -- I think this is the line that could be causing the problem.

--taking the folder identify which process it must follow.
if brandName is equal to "BRAND" then

      tell application "Adobe Photoshop CS2" --5.1"
            -- I remove the command activate, Photoshop stay in background
            set ruler units of settings to pixel units

            try
                  set myOptions to {class:JPEG save options, quality:12}
                  set myPSDOptions to {class:Photoshop save options, embed color profile:true, save layers:true}

                  tell (my getDocByPath(thefile))
                        set origName to name

                        --If the quick mask mode has been left on then delete the channel Quick Mask
                        if (quick mask mode) then delete channel ¬
                              "Quick Mask"
                        --If the Layer is incorrectly labeled with Original Layer it needs renaming to original Image
                        if (exists layer "Original Layer") then ¬
                              tell layer "Original Layer" to set name to "Original Image"
                        save in (localBrandFolder_PSD & origName) as Photoshop format with options myPSDOptions without copying
                        (delete layer "Original Image") flatten

                        resize image resolution 300 resample method none

                        --sharpen image
                        filter current layer using unsharp mask with options {amount:80, radius:3.2, threshold:0}

                        save in (localBrandFolder_High_Res & name) as JPEG with options myOptions without copying

                        --get file path, return path of the JPEG file, work with (without copying)
                        -- (with copying) : it return path of PSD file
                        set newFile to file path --( return path of type alias )

                        -- duplicate file using the Finder  -->on duplicateFile(..)
                        my duplicateFile(newFile, {ftpBrandFolder_High_Res})

                        --Prepare for Low RES by resetting image history
                        set current history state to history state 3

                        flatten

                        resize image width 1348
                        resize image resolution 300 resample method none
                        filter current layer using unsharp mask with options {amount:80, radius:3.2, threshold:0}

                        --add save to lowResFolder with same options
                        save in (localBrandFolder_Low_Res & name) as JPEG with options myOptions without copying
                   set newFile to file path --( return path of type alias )
                                                          set newFile2 to newFile as string -- for testing end of name

                        if newFile2 ends with "_2.jpg" or newFile2 ends with "_3.jpg" then -- exclude website_images
                              my duplicateFile(newFile, {networkBrandFolder_Low_Res, ftpBrandFolder_Low_Res})
                        else
                              my duplicateFile(newFile, {networkBrandFolder_Low_Res, ftpBrandFolder_Low_Res, website_images})
                        end if
                        close saving no
                  end tell
            end try

      end tell

      --End BH
end if
--then the next etc.

on duplicateFile(tFile, foldersPath) -- tFile is an alias, foldersPath is a list of folder
      tell application "Finder" to repeat with folderPath in foldersPath
            with timeout of 200 seconds -- adjust it,  error if the copy  is longer that 200 seconds
                  duplicate tFile to folder folderPath with replacing
            end timeout
      end repeat
end duplicateFile

on getFolderPath(tName, folderPath)
      tell application "Finder" to tell folder folderPath
            if not (exists folder tName) then
                  return (make new folder at it with properties {name:tName}) as string
            else
                  return (folder tName) as string
            end if
      end tell
end getFolderPath

on getDocByPath(tFile)
      set f to tFile as alias
      tell application "Adobe Photoshop CS5.1"
            repeat with i in (get documents)
                  if file path of i is f then return contents of i --return the doc
            end repeat
      end tell
end getDocByPath


If there is an error, give me the selected text in the editor and the error


Message was edited by: Jacques Rioux

Nov 23, 2012 2:17 AM in response to Jacques Rioux

It got a bit further


Its saving the PSD down and the High res only to the Images Volume all the folders have been created so disconnected drives.


Thanks


Matt


tell application "Adobe Photoshop CS5.1"


set ruler units of settings to pixel units

get every document

--> {document "FR10NW10305SV1RH.psd"}

get file path of document "FR10NW10305SV1RH.psd"

--> alias "Images:2012-2013:WK14:Freedom:Freedom_WK14_PSD:FR10NW10305SV1RH.psd"

get name of document "FR10NW10305SV1RH.psd"

--> "FR10NW10305SV1RH.psd"

get quick mask mode of document "FR10NW10305SV1RH.psd"


--> false

exists layer "Original Layer" of document "FR10NW10305SV1RH.psd"


--> false

save document "FR10NW10305SV1RH.psd" in "Images:2012-2013:WK15:FREEDOM:FREEDOM_WK15_PSD:FR10NW10305SV1RH.psd" as Photoshop format with options {class:Photoshop save options, embed color profile:true, save layers:true} without copying

--> document "FR10NW10305SV1RH.psd"

delete layer "Original Image" of document "FR10NW10305SV1RH.psd"

flatten document "FR10NW10305SV1RH.psd"


--> current application


resize imagedocument "FR10NW10305SV1RH.psd" resolution 300 resample methodnone


--> current application

filter current layer of document "FR10NW10305SV1RH.psd" using unsharp mask with options {amount:80, radius:3.2, threshold:0}


--> current application

get name of document "FR10NW10305SV1RH.psd"

--> "FR10NW10305SV1RH.psd"

save document "FR10NW10305SV1RH.psd" in "Images:2012-2013:WK15:FREEDOM:FREEDOM_WK15_HR:FR10NW10305SV1RH.psd" as JPEG with options {class:JPEG save options, quality:12} without copying

--> document "FR10NW10305SV1RH.jpg"

get file path of document "FR10NW10305SV1RH.psd"

--> error number -1728 from document "FR10NW10305SV1RH.psd"

end tell

Get current file of Photoshop.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.