Skip to main content
Participant
May 6, 2010
Question

Changes to Photoshop CS5 and Applescript

  • May 6, 2010
  • 9 replies
  • 35555 views

Looks like there are some major Applescript changes to CS5, which is unwelcome for anyone with existing scripts. From what I can see, the difference (that affect me anyway) are

a) PSCS5 seems to dislike referring to files with "as alias" and removing this from my scripts helps them to work, whereas other apps need it, as did previous

b) apparently script support for referring to the currently document has changed. "if visible layer of current document is true then..." no longer works, nor do document 0, document 1, etc. Anyone know how to refer to the current document?

c) support for history doesn't seem to be there anymore. I cannot seem to use AS commands like, "set myState to history states as list" or "set current history state to history state newState" were awesome for my workflow, but are they impossible to achieve now?

d) One more. The important "set docref to make new document with properties {height: 150, width: 150}" is also broken. How would one make a new document in Applescript?

This topic has been closed for replies.

9 replies

Participant
April 14, 2011

Hi, I am the original poster and it's funny that to do this day, doing a Google search on Applescript problems with CS5 brings up my post (I am honored). I'd like to tell Adobe in no uncertain terms the poor attention to Applescript cost them about 10 potential CS5 upgrades, and if CS6 continues to have broken scripts, without the ability to even tell the current document to do something, you will probably lose a customer for like (or, I'll stay at CS3 for the remainder of my company's lifespan). If I need to totalyl rework all my scripting from the ground up I'll find another tool to based my business around.

Adobe Employee
April 14, 2011

Peter, could you please give us an example to show the problems you encountered? Thanks a lot.

June 26, 2011

I am having a somewhat similar problem. I have a script that worked perfectly in CS4, except for the limitations of CS4 with printing. I have upgraded to the trial version of CS5 because supposedly the actions in CS5 record printing preferences. The following script worked PERFECTLY in CS4. Now when I run it in CS5 I get an error "Photoshop CS5.1 has an error: file some object wasn't found."

I didn't change ANYTHING in the script except for telling it to use CS5 instead of CS4, and the name of the action (because I made a new one in CS5)

on adding folder items to this_folder after receiving these_items
    
     try
          tell application "Finder"
               repeat with i from 1 to number of items in these_items
                    try
                         set this_item to item i of these_items
                        
                         tell application "Adobe Photoshop CS5.1"
                              open this_item
                              do action "deskjet9800" from "photobooth"
                             
                         end tell
                    on error error_message
                         tell application "Finder"
                              display dialog "Error for item " & (this_item as string) ¬
                                   & ": " & error_message buttons {"Continue", "Cancel"} ¬
                                   default button 1 giving up after 120
                         end tell
                    end try
               end repeat
          end tell
     on error error_message
          tell application "Finder"
               display dialog error_message buttons {"Cancel"} ¬
                    default button 1 giving up after 120
          end tell
     end try
    
end adding folder items to

Any help would be greatly appreciated. This is REALLY frusterating!!!

Oh, and I'm on a Mac, 10.5.8, with Photoshop CS5 12.1 x64

And I do have the scripting plug in in the automate folder.

And I tried removing the "do action" line, to see if Photoshop would just open the image, and got the same error.

Michelle

Participant
June 16, 2010

The plugin would be most helpful here too.

Please send to: arrowstotle    mac dot com.

Thanks in advance.

June 16, 2010

Please also send me the patch plug in.

tom dot thielke at qg dot com.

Thanks!

EdgeparkKen
Inspiring
June 10, 2010

I have a somewhat complex script that is performing a repeat and I don't understand why CS5 is broken on it.

tell application "Finder"
    -- make an item list from your identified folder
    set itemList to files in raw_folder
end tell

-- create a repeat that takes each file from the item list and do something
repeat with i from 1 to count of items of itemList
    tell application "Finder"
        set fileName to item i of itemList as alias
        --set itemPath to raw_folder & fileName
    end tell

    tell application "Adobe Photoshop CS5"
        set display dialogs to never
       
        activate
        open fileName

ScriptDebugger is reporting at this point the script starts. I have tried changing the last line to

open alias fileName but it still stops.

Is there really broken script communication between PSCS5 and OSX?

Adobe Employee
June 10, 2010

This is an example of dealing with the alias problem:

set appFolder to path to applications folder as string
set myPath to appFolder & "Adobe Photoshop CS5:Samples:"
tell application "Finder" to set fileList to name of files of folder myPath
set fileNum to count items of fileList

tell application "Adobe Photoshop CS5"
    activate
    set display dialogs to never
    repeat with i from 1 to fileNum
        open alias (myPath & item i of fileList)
    end repeat
end tell

The key is to coerce/cast the alias as "string" then in Photoshop coercing/casting it back to alias.

In your example, if you change the following lines, it should work for you:

In Finder:

set fileName to item i of itemList as alias => set fileName to (item i of itemList) as string

in Photoshop:

open fileName => open alias fileName

EdgeparkKen
Inspiring
June 10, 2010

Thank you so much!


Participant
May 31, 2010

I just installed PS CS5 and am unable to use my old applescript app for the reasons given above. I stupidly scrapped the former Photoshop (CS2) and am unable to reinstall it so I am really stuck. I tried editing the AS code and I could run it in XCode in debug mode but the syntax colour wouldn't show. The text remained black for new typing. Very strange. Other AS apps not involving CS5 still worked as expected.

Upon an error state I found that the Photoshop app had lost its Dictionary. (Applescript Editor came up blank.) Restarting Photoshop fixed this.

After much frustration I found this thread. Thanks. Please email the CS5 fix to mikey666*****at*****shaw*****dot*****ca.

Participant
June 1, 2010

Thanks for the prompt reply.

Participating Frequently
May 16, 2010

AppleScript support is effectively broken.

We have compiled scripts which fail to execute properly. Once this happens, every AppleScript command then fails including trying to compile new commands using the script editor (the 'current document' error mentioned above).

This breaks our application which was working great for years on CS3 and CS4.

Can we expect Adobe to fix this in a minor update of PS CS5?

Adobe Employee
May 14, 2010

In some situations Applescript Editor does run into communication problem with Photoshop. The safest way to make sure you will see all the terminologies in the library is to follow the steps below:

1. Save your script

2. Quit Applescript Editor

3. Quit Photoshop

4. Relaunch Photoshop

5. Open your saved script and recompile.

To make sure your script will run every time, you could save your compiled script as an Applescript app, then there is much less chance of getting into "Compiling errors."

For "as alias" problem, it had been identified the Standard library and Photoshop have different interpretation of the alias. To work around the problem, you could first cast the alias as "string", then in Photoshop cast it back "as alias." This should work around the current problem. For example:

set theImage to (choose file with prompt "Please select an image file:") as string  --This is from StandardAdditions of AppleScript Dictionary
tell application "Adobe Photoshop CS5"
   open alias theImage --"open file theImage" should work (w/o quote), too.
end tell

Participating Frequently
May 14, 2010

Thank you for this reply; I'll be sure to try the steps do see if I can reestablish a connection to Photoshop if it goes wonky after a lot of scripting.

I should have been more specific regarding document handling.

With CS4 I had no problem in setting a variable as a reference to the "front document", which I would then use via a tell statement; this would ensure that scripted actions were directed at a particular document, in case I inadvertently switched windows, or if the script action requires that the intended document actually is the front document.

It worked flawlessly in CS4; I cannot figure out how to do this in CS5.

Adobe Employee
May 14, 2010

Could you give me an example of what kind of problem you encountered?

Participating Frequently
May 7, 2010

Has anyone else noticed that all but the standard command suites are missing? Drag-drop CS5 onto the AppleScript Editor icon and see if there's more than "Standard Suite", "Text Suite" and "Type Definitions".

My scripts in CS5 generally run with some modification, but the commands not in these dictionaries are called by event code, not standard AppleScript.

Also, I've noticed that they've changed the way they refer to the active document, but without the proper dictionaries, I can't develop a workaround.

I really hope Adobe doesn't sit on this until CS6 -- it's quite a dealbreaker.

Participating Frequently
May 6, 2010

They seem to have removed a huge number of AppleScript features, and the dictionary is basically empty. The developer center doesn't have any info on CS5 either: http://www.adobe.com/devnet/photoshop/scripting/ So apparently they expect us to just guess at what works.

Presumably they want us to start using JavaScript instead of AppleScript. But the worst part is that the "do javascript" command is apparently gone as well, which would have at least given us an easy way to transition existing scripts.

What a disaster.

Participating Frequently
May 6, 2010

I just found the AppleScript documentation in /Applications/Adobe Photoshop CS5/Scripting/Documents/. But I don't think it's even accurate. Here's a very simple sample they give:

tell application "Adobe Photoshop CS5"      filter current layer of the current document using lens blur with options {class:lens blur, radius:13} end tell

If I enter this in AppleScript Editor and try to compile it, it selects the word "current" and tells me "Expected end of line but found identifier." It doesn't even recognize "filter" as a command. If I just change that 5 to a 4, it works fine in CS4.

Here's one way to run a JavaScript file from AppleScript:

tell application "Adobe Photoshop CS5" to open file "Path:to:file.jsx"

Of course there's no way to pass any arguments this way, so that greatly limits its usefulness. But perhaps this will be helpful to some people. I'm assuming the JavaScript stuff all works fine, as that seems to be their focus these days.

The really strange thing is that certain things seem to work fine in AppleScripts that are already compiled (using CS4). But if I try to re-save those scripts with CS5 installed, I get errors.

Inspiring
May 7, 2010
I'm assuming the JavaScript stuff all works fine, as that seems to be their focus these days.

It doesn't surprise me that there are errors in Applescript and/or it's documentation. There are errors in both javascript and it's guides.

I would surprise me if those errors are intentional to force anyone to switch to javascript.

My guess would be that any new Applescript errors are a result of either the Apple forced API change or the change to 64 bit. That combined with the fact that there are fewer Applescript developers for Photoshop to report any errors when the product was in prerelease.

I reported several javascript errors during the prerelease. Most where not fixed. I didn't assume that was because Adobe didn't want javascript developers. I assumed that they did not have time or resources to deal with those because of the other work needed for this cycle.