scripting system error -1751 ?

I have two test applescripts. badtest is:



set input_folder to "d2:Users:data:goes color:east:incomingimages"

property type_list : {"TIFF"}
property extension_list : {"tif", "tiff"}

tell application "Finder"
set FinderRef to a reference to ((items of folder input_folder) whose ¬
file type is in type_list or name extension is in extension_list)
end tell





while goodtest is:


set input_folder to "d2:Users:data:goes color:east:incomingimages"

property type_list : {"TIFF"}
property extension_list : {"tif", "tiff"}

tell application "Finder"
set FinderRef to a reference to ((items of folder input_folder))
end tell



The only difference between the two is the file type and extension check in badtest. Both run fine as scripts in the editor, but when I save them as apps and doubleclick them to run, goodtest run fine, while badtest seems to run correctly (it gets the correct list of files) but then generates the following script error:

"Could not save changes to this script because of a scripting system (OSA) error -1750"

Any suggestions as to what I'm doing wrong? I'm fairly new to applescripting so I'm hoping I'm making a really obvious mistake of some sort.

This is on 10.4.5 with the latest security update and script editor version 2.1.1 (81)

G5 dual 2 GHz

Posted on Mar 17, 2006 9:55 AM

Reply
3 replies

Mar 17, 2006 1:11 PM in response to Marit Jentoft-Nilsen

Just before a script quits, the application running the script automatically saves any variables the script defined while it was running. You've found a way, however, to define a variable whose contents can be assigned, but can't be stored for future runs. This is odd.

Investigating further, it appears the culprit is any variable that contains a reference to the result of an object filter. Example:

click here to open this script in your editor <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">tell application "System Events"
set x to a reference to (processes whose name is "Finder")
end tell</pre>Setting x to a blank string at the end of the script will prevent the error from occurring, as will removing the source of the problem ( a reference to) which I think is only hiding some bigger problems in your object filter.

Mar 17, 2006 1:40 PM in response to Michael Henley

Thanks - setting the variable to a blank string works.

Of course even though my short term problem is fixed, now there are even more questions I'll eventually have to answer to be sure I'm writing reliable scripts.

One thing that isn't entirely clear is that you found another example that triggers the error, but then say there are "bigger problems in your object filter". Does that mean I'm using the object filter incorrectly or is (a reference to) a deprecated or obsolete applescript feature? I guess I need to start studying applescript documentation in my spare time.

Thanks again for your help


G5 dual 2 GHz

Mar 17, 2006 2:36 PM in response to Marit Jentoft-Nilsen

The only problem here may simply be that the reference is connected to code that's executed each time the reference is called. Whereas your script may be able to resolve the referenced code while running normally, OSA probably can't do that at quit time (at least not for certain types of code).

As for reliable scripting, the use of a reference to requires extra care, because using it allows you to disguise illegal code while testing in Script Editor.

Here I'm trying to filter a list object. Filtering a list using whose is against the rules, but the Script Editor compiler doesn't know this, and we'll only find out after we try and fail:

click here to open this script in your editor <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">items of {} whose {} is in {}</pre>But if we wrap the same code in a reference that's never resolved, the script goes off without a hitch:

click here to open this script in your editor <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">a reference to (items of {} whose {} is in {})</pre>So yeah, as a general rule, if you don't have a good reason for using a reference to, it's probably best to avoid it.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

scripting system error -1751 ?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.