8 Replies Latest reply: Jul 27, 2012 8:47 AM by twtwtw
MattJayC Level 1 Level 1 (0 points)

Hi I am process a mass of files, and the script works, but a few files are locked how can I add it to this script

 

tell application "Finder"

          set theseFiles to files of front Finder window as alias list

          repeat with tFile in theseFiles

                    set tFile to tFile as string -- convert alias to string for Photoshop CS5+

 

--unlock file if locked

 

 

  --Run photoshop action

 

                    tell application "Adobe Photoshop CS5.1"

                              try

  open (alias tFile) showing dialogs never

                                        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 (exists layer "Original Layer") then ¬

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

  --If Original Image layer exists, then delete

                                                  delete layer "Original Image"

 

                                                  do action "Merge Layers" from "PSD Compression"

 

  close saving no

 

                                        end tell

                              on error

                                        set noError to false

                                        my myLogs(tFile) -- write path to log file in Desktop

                                        try

  close saving no --if exists, close current document

                                        end try

                              end try

 

 

                    end tell

          end repeat

end tell

if not noError then do shell script "/usr/bin/open  ~/Desktop/LogPhotoshopError.txt'"

 

 

on myLogs(t)

          try

                    do shell script "echo " & (quoted form of t) & ">> ~/Desktop/LogPhotoshopErrorfromPSDCOMP.txt'"

          end try

end myLogs

 

 

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

tell application "Finder"

          open "Hal 9000:Users:matthew:Desktop:LogPhotoshopErrorfromPSDCOMP.txt"

end tell


iMac, Mac OS X (10.6.8)
  • 1. Re: add a file unlock to an applescript.
    twtwtw Level 5 Level 5 (4,690 points)

    assuming you have permission to unlock the file, you can use the Finder's item's lock property"

     

    tell application "Finder"

              set lock of tFile to false

    end tell

     

    as an aside, let me point out that it's generally bad practice to nest application tell blocks.  Most of the time it works, yes, but when it doesn't it's bear to debug.  My general practice in situations like yours is to create a handler for the Photoshop tell block and call it from the Finder tell block; using a handler creates a new context that eliminates the possibility of name conflicts.

  • 2. Re: add a file unlock to an applescript.
    MattJayC Level 1 Level 1 (0 points)

    Not getting that to work for at the moment,

     

    When I add it where  I suggested, it just opens the items, but doesn't do anything?.

     

    any quick suggestions? Many Thanks

    Matt

  • 3. Re: add a file unlock to an applescript.
    twtwtw Level 5 Level 5 (4,690 points)

    The only suggestion I have is for myself to get glasses.  The property name is 'locked' not 'lock' - set locked of tFile to false.

  • 4. Re: add a file unlock to an applescript.
    MattJayC Level 1 Level 1 (0 points)

    I get the error

    error "Can’t set locked of \"Images:2011-2012:WK40:Wallis_WK40_PSD:WA35WW02747GO1GO.psd\" to false." number -10006 from locked of "Images:2011-2012:WK40:Wallis_WK40_PSD:WA35WW02747GO1GO.psd"

     

     

    Result:

    error "Can’t set lock of \"Images:2011-2012:WK40:Wallis_WK40_PSD:Error Log.txt\" to false." number -10006 from lock of "Images:2011-2012:WK40:Wallis_WK40_PSD:Error Log.txt"

  • 5. Re: add a file unlock to an applescript.
    twtwtw Level 5 Level 5 (4,690 points)

    You've given two different error outputs - the first says 'locked' and the second says 'lock'  which is correct?

     

    The Finder dictionary claims that items have a boolean 'locked' property, and that it is read/write.  If it's not working, then either Finder scripting has a bug or Photoshop locks the file in a way that Finder can't undo.  either way you'll have to turn to photoshop and see if it has a way of unlocking files - I don't have PS available currently, so I can't help with that.

  • 6. Re: add a file unlock to an applescript.
    Jacques Rioux Level 4 Level 4 (1,960 points)

    Hi,

     

    MattJayC wrote:

     

    I get the error

    error "Can’t set locked of \"Images:2011-2012:WK40:Wallis_WK40_PSD:WA35WW02747GO1GO.psd\"

     

    Because tFile is a string.

    As shown in this post,  maybe you must change the modification date of file.

     

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

    set currDate to current date

    tell application "Finder"

        set theseFiles to files of front Finder window as alias list

        repeat with tFile in theseFiles

            set locked of tFile to false

            set modification date of tFile to currDate

            set tFile to tFile as string -- convert alias to string for Photoshop CS5+

  • 7. Re: add a file unlock to an applescript.
    MattJayC Level 1 Level 1 (0 points)

    This is from the on screen prompt

     

    Can’t set locked of "Images:2011-2012:WK30:Freedom:Freedom_WK30_PSD:FR10RI03653GO1AG.psd" to false.


    and then in Result field

     

    error "Can’t set locked of \"Images:2011-2012:WK30:Freedom:Freedom_WK30_PSD:FR10RI03653GO1AG.psd\" to false." number -10006 from locked of "Images:2011-2012:WK30:Freedom:Freedom_WK30_PSD:FR10RI03653GO1AG.psd"

     

     

    I think I might be running in to another problem where my files have already gone though the process. Like you mentioned earlier i might have too many things going on.

  • 8. Re: add a file unlock to an applescript.
    twtwtw Level 5 Level 5 (4,690 points)

    I don't think changing the modification date will be necessary, but you're right about the value being a string - I missed that.  In that case all he need to do is toss in a 'file' keyword:

     

    tell application "Finder"

      -- ...

              set locked of file tFile to false

      -- ...

    end tell