AS won't save a file it will run

I’ve got a problem for you guru’s…

I’ve got a script that works primarily in photoshop elements 4 (which just became scriptable with this version.) At first, I could not get the script to compile because PSE4 uses the term “as” as a property in some instances.


tell application "Photoshop Elements 4.0"
	set myoptions to {class:save for web export options, as:JPEG, interlaced:true, quality:70}
	export current document in "Random HD:annoying.jpg" as save for web with options myoptions
end tell

The ScriptEditor chokes, claiming that “as” is not a property even if it is in the PSE4 dictionary. The wizards over at the photoshop forum suggested I replace the code “as” with the raw form “«class fltp»” This was great because the script now runs perfectly, with the annoyance that every time it runs it replaces “«class fltp»” with “as” which needs to be retyped in order to run a second time.

The bad news is that the Applescript editor will not SAVE the script. If I try to save the version of the script that runs I get the following error in a dialog box “The document ‘docname’ cannot be saved.” I have to comment out the code that contains “«class fltp»” in order to save it.

How can I workaround this problem? Thanks in advance.

Hi, tls.

If that’s the correct syntax, it’s bad that it doesn’t compile. The following work-round works in principle, but I don’t know if it works with PhotoShop Elements 4.0 in particular. The idea is that the handler compiles a mini-record with an ‘as’ property, so that if you feed it the string “JPEG”, it will return {as:JPEG}. This happens when the script’s run, which should bypass the problem of saving it ready-compiled. The record’s then concatenated to the other options in the main part of the script.

But I don’t have a copy of PE4 with which to test it… :expressionless:

on compileAsOption(valStr)
	tell application "Photoshop Elements 4.0"
		run script "tell application \"Photoshop Elements 4.0\" to return {«class fltp»:" & valStr & "}"
	end tell
end compileAsOption

tell application "Photoshop Elements 4.0"
	set myoptions to {class:save for web export options, interlaced:true, quality:70} & my compileAsOption("JPEG")
	export current document in "Random HD:annoying.jpg" as save for web with options myoptions
end tell

That is a clever solution. More importantly, it works.

Just out of curiousity, who should I be irritated with for this bug, Apple or Adobe? Perhaps there is enough blame to be spread around, but I like to keep my indignation focused. :slight_smile:

Thanks for your assistance. My family thanks you too… the code is something I am playing with to automate the process of adding pictures of our infant daughter to a website to be viewed by far-flung family.

Without seeing the application’s dictionary for myself, I wouldn’t like to pronounce on the matter. :rolleyes: On the face of it, it would seem to be Adobe’s fault for using an AppleScript reserved keyword as a property name. On the other hand, you’d expect that someone on their AppleScript team would have tested it to see if it worked…

This is also an issue in PhotoShop CS2 for the same save as web command, even though the PhotoShop dictionary says to use “as”. It seems to be a bug by Adobe.

I like your solution Nigel. I have been putting in “«class fltp»:JPEG” in my PhotoShop script, which means EVERY time I need to make an edit I have to go back and replace “as” with «class fltp» and re-compile. Very awkward. I am going to try your subroutine and make my Photoshop script easier to work with.

Thanks.

Model: Mac G5 OS 10.3.9
Browser: Safari 312.3.1
Operating System: Mac OS X (10.3.9)