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?
I'd appreciate any help you could give me in updating my scripts
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.
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.
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.
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:
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.
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.
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.
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.
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
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.
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
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?
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?
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
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
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.
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.
North America
Europe, Middle East and Africa
Asia Pacific