Re: How do you eval strings as enumerators in 10.6?
Re: How do you eval strings as enumerators in 10.6?
- Subject: Re: How do you eval strings as enumerators in 10.6?
- From: Christopher Nebel <email@hidden>
- Date: Tue, 21 Dec 2010 17:06:25 -0800
On Dec 16, 2010, at 8:10 AM, David Jacopille wrote:
> 10.6 appears to have a problem evaluating strings using 'run script' that 10.4 and 10.5 did not have. The example is Illustrator, but, correct me if I'm wrong, this is a generic problem or difference with 10.6.
>
> If I were to hard code what I want to do in the script it would look like this, which creates a new spot color swatch as expected:
>
> tell application "Adobe Illustrator"
> make new document
> tell document 1 to make new spot with properties {name:"Light Yellow", color:{cyan:0, magenta:0, yellow:25, black:0}, color type: process color}
> end tell
>
> Note that the value of name is class 'text' and is in quotes, but the value of color type is not in quotes - it is an Adobe Illustrator enumeration.
>
> But I don't want to hard code enumerated values in my script - I want my parameters to come from an XML file or database which means it has to be stored as a string. This simulates what I want to do:
>
> set color_type to "process color"
> tell application "Adobe Illustrator"
> make new document
> tell document 1 to make new spot with properties {name:"Light Yellow", color:{cyan:0, magenta:0, yellow:25, black:0}, color type:(run script color_type)}
> end tell
>
> Works great in 10.4 and 10.5. In 10.6 this results in "Adobe Illustrator got an error: An error of type -30002 has occurred."
>
> Any ideas about how to evaluate strings to enumerators in 10.6?
The issue has to do with scripting addition security and where scripting additions such as "run script" actually execute. You're using "run script" as a general text-to-value converter, which is fine. The tricky bit is that by telling Adobe Illustrator to do it, it executes inside Illustrator itself, which means Illustrator's terminology is implicitly in scope -- it's as if the whole script is wrapped in a 'tell application "Illustrator"' block -- so "process color" can successfully be compiled.
At least, that's what it used to do. The security changes in 10.6 cause "run script" to actually execute in application that's running the script -- if you watch the event log, you can see it re-trying "run script" in the current application. Executing in a different process means no implicit tell-Illustrator means you can't compile Illustrator-specific terms. The solution is simply to be explicit about what you were doing implicitly before: in other words, add an explicit "tell" to the script you hand to "run script", something like this:
set color_type to "process color"
set value_script to "tell application \"Adobe Illustrator\" to " & color_type
tell application "Adobe Illustrator"
make new document
tell document 1 to make new spot with properties {name:"Light Yellow", color:{cyan:0, magenta:0, yellow:25, black:0}, color type:(run script value_script)}
end tell
You can use this trick on any system, 10.6 or otherwise, it's merely superfluous on 10.5 and earlier.
--Chris Nebel
AppleScript Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden