Search code examples
applescriptphotoshopextendscriptfinderosascript

AppleScript generates an unknown error which is not listed in the reference table


I get this error: test.scpt: script error -41. Couldn't get error text because of error -1700.

AppleScript contents:

tell application "Adobe Photoshop CC 2019"
activate
set js to "#include '/Users/temp_myname/My Application/tmp/Adobe Scripts/script.jsx';" & return
delay 3
do javascript js
end tell

JSX script contents:

#target photoshop
var err = "";
app.bringToFront();
app.displayDialogs = DialogModes.ERROR;
var fileRef = new File("/Users/temp_myname/My Application/tmp/10.20.5.18/default_10/Images/889original.jpg");
try{
open(fileRef);
} catch (Error) { err = Error }
;fileRef = null;
var errorFile = new File("/Users/temp_myname/My Application/tmp/Adobe Scripts/psperr.txt");
errorFile.open("w");
errorFile.write(err);
errorFile.close();
errorFile = null;

function runMenuItem(item) {
cTID = function(s) { return app.charIDToTypeID(s); };var desc = new ActionDescriptor();var ref = new ActionReference();ref.putEnumerated( cTID( "Mn  " ), cTID( "MnIt" ), item );desc.putReference( cTID( "null" ), ref );executeAction( cTID( "slct" ), desc, DialogModes.NO );
}

OSX Version: 10.14.6

How can this script generate the error code -1700? the same script works on another Mac (with the same configuration) just fine.

What does -41 mean? I can't find it in the reference table:

Error Numbers and Error Messages

From that page I got the description for error code -1700:

Bad parameter data was detected or there was a failure while performing a coercion.

I checked the file permissions, reset the Finder, disabled the virusscanner, unmounted volumes... I also added the osascript and extendscript executables to the system security settings.

What do you think? How can I make this work?

BTW. I run the AppleScript from a Java application that uses OpenJDK, like this:

Runtime rt = Runtime.getRuntime();
Process proc;
String[] process;

process = new String[2];
process[0] = "osascript";
process[1] = "/Users/temp_myname/My Application/tmp/Adobe Scripts/test.scpt";
proc = rt.exec(process);

Solution

  • This has been fixed. The trick is to add a sleep between the execution of two such AppleScripts.

    Error code -41 is an OSX error code that can be found in MacErrors.h: mFulErr = -41, /memory full (open) or file won't fit (load)/