Skip navigation
Currently Being Moderated

Changes to Photoshop CS5 and Applescript

May 6, 2010 12:01 AM

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?

 
Replies 1 2 Previous Next
  • Currently Being Moderated
    May 6, 2010 1:45 PM   in reply to Peter Payne

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 6, 2010 2:40 PM   in reply to robotspacer

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 7, 2010 8:48 AM   in reply to robotspacer
    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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 7, 2010 9:24 AM   in reply to Michael L Hale

    Yeah, after investigating it further I think it's just buggy, as opposed to having features intentionally removed. I was finally able to get a complex script working again with minimal changes by doing this:

     

    • Installed Photoshop CS4 again.
    • Had my scripts call "Adobe Photoshop CS4" or just "Adobe Photoshop CS" rather than CS5.
    • If I was ever asked to locate Photoshop while compiling, I selected CS4, not CS5. Selecting CS5 here, or calling "Adobe Photoshop CS5" in the script will result in major errors.
    • Once the script was compiled (saved), I moved my Photoshop CS4 folder to the trash (without emptying it). This made sure the script ran in CS5. Then if I needed to make further changes, I could just drag CS4 out of the trash and back into place.
    • It was also a big help to add [b]try… on error… end try[/b] blocks around things that seemed to be causing problems in CS5.

     

    Peter, hopefully this will help you too. By doing the above I've found that "current document", "as alias", and other things work as expected in CS5, even though they were previously giving me errors.

     

    Can anyone tell us the best place to report these bugs? I'd love to do what I can to help them get fixed.

     
    |
    Mark as:
  • Currently Being Moderated
    May 7, 2010 9:55 AM   in reply to robotspacer

    You should be able to report bugs here https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

     

    You will need an Adobe ID, which you should already have.

     
    |
    Mark as:
  • Currently Being Moderated
    May 7, 2010 12:09 PM   in reply to Peter Payne

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 7, 2010 12:46 PM   in reply to Michael L Hale

    Thanks Michael, I just filed a bug report:

     

    ******BUG******

    Concise problem statement:

    Photoshop CS5 for Mac has some major issues with AppleScript. Most (but not all) scripts seem to run okay, but all of the custom commands are missing from the dictionary, and almost nothing will compile. The only workaround I've found is to install CS4, compile against that, then run the script with CS5.

     

    Steps to reproduce bug:

     

    1. Open AppleScript Editor

    2. Enter a simple script from the AppleScript guide, like:

    tell application "Adobe Photoshop CS5"

         filter current layer of the current document using lens blur with options {class:lens blur, radius:13}

    end tell

    3. Click Compile or Run.

     

    Results:

    An error occurs: "Expected end of line but found identifier."

     

    Expected results:

    The script should compile with no errors, or run--applying a lens blur to the front-most document in Photoshop CS5.

     

    If CS5 is changed to CS4, the script works perfectly. (If it the script is saved as an application and CS4 is deleted, it will probably even work in CS5. Compiling is the main issue.)

     

    For anyone else having problems I'd encourage you to do the same.

     
    |
    Mark as:
  • Currently Being Moderated
    May 13, 2010 5:55 PM   in reply to Peter Payne

    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

     
    |
    Mark as:
  • Currently Being Moderated
    May 13, 2010 6:45 PM   in reply to JonLo

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 13, 2010 10:52 PM   in reply to Sideways Design

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

     
    |
    Mark as:
  • Currently Being Moderated
    May 14, 2010 4:58 AM   in reply to JonLo

    Try this:

     

    tell application "Adobe Photoshop CS4"

    set psDocRef to front document

    end tell

     

    and then try this:

     

    tell application "Adobe Photoshop CS5"

    set psDocRef to front document

    end tell

     
    |
    Mark as:
  • Currently Being Moderated
    May 14, 2010 9:16 AM   in reply to Sideways Design

    For AppleScript, you could use "current" to set focus to the frontmost object. So, you could change the focus by using "current" as follows:

     

    tell application "Adobe Photoshop CS5"

        activate

        set psDocRef to make new document -- first document has the focus

        make new document -- now, second document has the focus

        set current document to psDocRef -- the first document get the focus again.

    end tell

     
    |
    Mark as:
  • Currently Being Moderated
    May 16, 2010 3:31 AM   in reply to Peter Payne

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    May 16, 2010 9:06 PM   in reply to JonLo

    Ah—making sure to launch Photoshop CS5 before AppleScript Editor (or Xcode) does seem to fix the problems for me. The dictionary shows up correctly, and the compiling errors are gone. Thank you!

     
    |
    Mark as:
  • Currently Being Moderated
    May 17, 2010 1:12 PM   in reply to robotspacer

    This sounds like an issue where the Photoshop terminology gets dropped on the floor because Cocoa installs its own terminology handler on top of Photoshop's handler.

    If I follow the steps described in this thread, then I do not see the problem on my machine.

    My test case is:

    - Launch the AppleScript Editor

    - Enter:

     

    tell application "Adobe Photoshop CS5"

    make new document

    filter current layer of the current document using lens blur with options {class:lens blur, radius:13}

    end tell

    - Click compile (or hit enter)

    Photoshop launches and the script compiles correctly

     

     

    There could be some OS version sensitivity here. I am currently testing on 10.6.3.

    Could you let me know which version of OSX that you are using?

     
    |
    Mark as:
  • Currently Being Moderated
    May 18, 2010 9:02 AM   in reply to robotspacer

    Besides information about the OS version could you also let me know:

    - whether or not your are running in 32 bit mode

    - which 3rd party plug-ins (if any) you are using

    - which scripting additions that you are using

    Thanks,

    Jesper

     
    |
    Mark as:
  • Currently Being Moderated
    May 19, 2010 12:19 PM   in reply to Jesper Storm Bache

    - Mac OS X 10.6.3 french, CS5 french

    - 64 bits mode

    - no third parties plug-ins

     

    OSAXEN : Adobe Unit Types.osax (from cs5 installation), Satimage.osax,XMLLib.osax (both are from sati image), SIMBL.osax,SmartScroll.osax,XMLLib.osax,TextExpander Addition.osax

     
    |
    Mark as:
  • Currently Being Moderated
    May 19, 2010 12:57 PM   in reply to Jesper Storm Bache

    - Mac OS X 10.6.3, CS5 French

    - 64-bit (iMac Core 2 Duo)

    - No third-party plugin

    - No scripting addition

     
    |
    Mark as:
  • Currently Being Moderated
    May 20, 2010 6:52 AM   in reply to SMP_Vince

    D'accord.

    Besides using a French version of Photoshop you should have the same version as I do. Could I ask you to post specific steps on how to repro from system restart to failure?

    You'll see me test case earlier in this thread & that case does not fail on my system.

    Thank you,

    Jesper

     
    |
    Mark as:
  • Currently Being Moderated
    May 20, 2010 7:12 AM   in reply to Jesper Storm Bache

    Test case:

     

    1. Place an "image.tif" on your desktop

    2. Open another image in Photoshop

    3. Run the following script

     

     

    tell application "Adobe Photoshop CS5"

    activate

    set masterDocument to current document

    open file ((path to home folder as string) & "Desktop:image.tif")

    height of masterDocument

    end tell

     

     
    |
    Mark as:
  • Currently Being Moderated
    May 20, 2010 7:29 AM   in reply to tomdev

    Just did Error

     

     

     

    error "Erreur dans Adobe Photoshop CS5 : Il est impossible d’obtenir current document." number -1728 from current document

     
    |
    Mark as:
  • Currently Being Moderated
    May 20, 2010 10:56 AM   in reply to SMP_Vince

    Thanks for the repro steps.

    It appears that the "open" command affects the terminology.

    In the following script the first "height of current document" works, while the second fails:

     

    tell application "Adobe Photoshop CS5"

    activate

    height of current document

    open file ((path to home folder as string) & "Desktop:image.tif")

    height of current document

    end tell

    When we are in the failure mode everything fails so it does appear that Cocoa in some way is overriding our event handlers.
    Again thanks for reporting this issue and providing a test case.

     
    |
    Mark as:
  • Currently Being Moderated
    May 20, 2010 11:49 AM   in reply to Jesper Storm Bache

    I'm glad to see you're getting what is going wrong.

    If I can be of any help, please tell me! I'd love to see this fixed.

     

    Thanks!

     
    |
    Mark as:
  • Currently Being Moderated
    May 21, 2010 2:47 PM   in reply to tomdev

    Based on the test case from this thread, we have been able to make some changes that solves the problems that we are seeing.

    If you post your email I'd be happe to email you a pre-release version of the changes so you can verify whether or not it solves the problems that you are seeing on your system (the size is between 3 and 4 MB).

    If you do post your email address make sure to scramble it slightly to minimize the risk of getting spam from web-crawlers.

    For example: "tom" at "company dot fr"

    Again, Thanks for your help.

     
    |
    Mark as:
  • Currently Being Moderated
    May 21, 2010 3:02 PM   in reply to Jesper Storm Bache

    Excellent, that was quick.

    I'd be happy to test and report back to you.

    I just sent you a private message with my e-mail address, is that ok?

     
    |
    Mark as:
  • Currently Being Moderated
    May 21, 2010 4:31 PM   in reply to Jesper Storm Bache

    Please send it at "vincentdigitallife"  gmail  dot com

     
    |
    Mark as:
  • Currently Being Moderated
    May 21, 2010 5:23 PM   in reply to Jesper Storm Bache

    I'd be happy to kick it around, too.

     

    richard (at) sidewaysdesign (dot) com

     
    |
    Mark as:
  • Currently Being Moderated
    May 21, 2010 5:53 PM   in reply to Jesper Storm Bache

    For what it's worth I am no longer able to reproduce the problems I was having. It was happening very consistently until I reinstalled Photoshop CS4. Now, even after uninstalling CS4 again, I can't recreate the problem.

     
    |
    Mark as:
  • Currently Being Moderated
    May 24, 2010 2:58 AM   in reply to Jesper Storm Bache

    New plugin works great for me, thanks a lot !

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2010 10:36 AM   in reply to Jesper Storm Bache

    hoping to try this patch as well. this bug has put a halt on my workflow

     

    trapdoormg at gmail.com

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2010 10:51 AM   in reply to null_node

    thank you for the incredibly fast response jesper. the plugin solved my problems!!

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2010 11:20 AM   in reply to null_node

    You are welcome.

    Thank you for letting us know that this change fixes the problem that you are encountering.

    Jesper

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2010 3:42 PM   in reply to Jesper Storm Bache

    When can we expect this patch to be pushed to every CS5 user out there?

     
    |
    Mark as:
  • Currently Being Moderated
    May 31, 2010 2:33 PM   in reply to Peter Payne

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 1, 2010 11:58 AM   in reply to surreysud

    Thanks for the prompt reply.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 2, 2010 12:35 PM   in reply to Jesper Storm Bache

    Hi Jesper,

     

    I ran across this discussion searching for a fix to my applescripting errors with Photoshop CS5. I was wondering if I could get that beta fix as well. You can email it to me at chrisbernal.design [at] gmail.com

     

    Thanks in advance.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 2, 2010 1:18 PM   in reply to Jesper Storm Bache

    Hey Jesper,

     

    Thanks for the fast response. Just wanted to let you know that the updated plugin fixed all of my errors.

     

    Thanks again.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 2, 2010 1:20 PM   in reply to Cut Copy Design

    Excellent & thanks for letting me know.

    Jesper

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 9, 2010 8:07 AM   in reply to Jesper Storm Bache

    Please also send me the patch plug in.

     

    chris.paveglio *at*  clippermagazine  *dot* com

     
    |
    Mark as:
1 2 Previous Next
Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points