Skip to main content
Known Participant
August 22, 2013
Question

AppleScript 'current document' seems to be broken in Photoshop CC

  • August 22, 2013
  • 1 reply
  • 4115 views

I'm using AppleScript to control Photoshop's web export, on a Mac running OS X 10.8.4. Essentially, I want to open a document and resave it using the Web Export options.

The following script snippet worked fine in Photoshop CS5:

on process_item(this_item)

          set thePath to this_item as string

          tell application "Adobe Photoshop CS5"

  open alias thePath

                    set theDocument to current document

  export theDocument in thePath as save for web with options {web format:JPEG, quality:60}

  close theDocument saving no

          end tell

end process_item

However, if I change the application name to "Adobe Photoshop CC", then the script stops working. As soon as it reaches the request for 'current document', Applescript throws an error:

   "Can't get document 'somedocument.jpg' of application "Adobe Photoshop CC".

where 'somedocument.jpg' is the name of my document. Note that AppleScript (or Photoshop) is aware of the document at some level - it shows the correct name. It just can't "get" it, and the whole process grinds to a halt.

If I open the document manually, then run an Applescript that just does the

  set theDocument to current document

command, Photoshop gets the document object without difficulty.

I've tried inserting a delay after opening the file, or using different ways to refer to the current document. I've verified that Photoshop is actually aware of open documents by using 'count' to find out how many documents are open. However, nothing I can think of will make this previously functional script work with Photoshop CC.

Has anyone encountered this problem or found a workaround? Thanks.

This topic has been closed for replies.

1 reply

Known Participant
August 22, 2013

I've been able to narrow the problem down further.

The following snippet:

    tell application "name-of-photoshop" to export current document in "~/1.jpg" as save for web with options {web format:JPEG, quality:60}

will work correctly where name-of-photoshop = "Adobe Photoshop CS5", and will fail if name-of-photoshop = "Adobe Photoshop CC".

Adobe Employee
August 22, 2013

Hi there,

Could you please change your script as follows:

on process_item(this_item)

          set thePath to this_item as string

          tell application "Adobe Photoshop CC"

  open alias thePath

                    set theDocument to current document

  export theDocument in thePath as save for web with options {class:save for web export options, web format:JPEG, quality:60}

  close theDocument saving no

          end tell

end process_item

I found this is working for me. If you still have any problem, please let me know. Thanks.

Known Participant
August 22, 2013

Thank you, Jon.

That seems to resolve the issue.

I don't suppose there's a hidden option to control whether metadata is saved or not (and which metadata)? There doesn't seem to be an option to control this documented as part of the 'save for web export options' class, but perhaps it's an undocumented feature. It certainly seems like something that belongs there.