11 Replies Latest reply: Jan 15, 2013 1:18 AM by MattJayC
MattJayC Level 1 Level 1 (0 points)

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 (alias thefile) showing dialogs never

                              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"

  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

                                        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


iMac, Mac OS X (10.6.8)
  • 1. Re: Get current file of Photoshop.
    MattJayC Level 1 Level 1 (0 points)

    Can any one help with this?

  • 2. Re: Get current file of Photoshop.
    MattJayC Level 1 Level 1 (0 points)

    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 dialog DocumentName

    end tell

     

     

    set thefile to DocumentName

  • 3. Re: Get current file of Photoshop.
    Jacques Rioux Level 4 Level 4 (1,960 points)

    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"

          set theDoc to current document

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

    end tell

    ----------

     

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

  • 4. Re: Get current file of Photoshop.
    MattJayC Level 1 Level 1 (0 points)

    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


  • 5. Re: Get current file of Photoshop.
    Jacques Rioux Level 4 Level 4 (1,960 points)

    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"

          set thefile to (file path of current document) as text --> get the file path

    end tell

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

     

    Add this handler to the end of the script.

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

    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

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

     

    Replace all  'current document' in rest of your script by (my getDocByPath(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

  • 6. Re: Get current file of Photoshop.
    MattJayC Level 1 Level 1 (0 points)

    I replaced this

        

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

                    set theDoc to current document

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

                   end tell

     

    With what you posted and then the bit at the bottom.

    I'm currently getting a missing value.

     

    I think it as theDoc is not set and also thefile  is already used?

  • 7. Re: Get current file of Photoshop.
    Jacques Rioux Level 4 Level 4 (1,960 points)

    Maybe this:

     

    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
    
    

     

    After that, I no longer have any idea to work around this bug

  • 8. Re: Get current file of Photoshop.
    MattJayC Level 1 Level 1 (0 points)

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

    open (alias thefile) showing dialogs never

     

    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.

  • 9. Re: Get current file of Photoshop.
    Jacques Rioux Level 4 Level 4 (1,960 points)

    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

  • 10. Re: Get current file of Photoshop.
    MattJayC Level 1 Level 1 (0 points)

    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 image document "FR10NW10305SV1RH.psd" resolution 300 resample method none

      --> 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

  • 11. Re: Get current file of Photoshop.
    MattJayC Level 1 Level 1 (0 points)

    Decided to revisit this topic, it kept stalling on a lot of areas of photoshop like the history step amoung other things,

     

    I had a rethink and used your code to get the current document, save it to a temp location then reopen process and delete and that seams to have it all running smoothly