RE: Snow Leopard osax security and 'run script' with parameters
RE: Snow Leopard osax security and 'run script' with parameters
- Subject: RE: Snow Leopard osax security and 'run script' with parameters
- From: Scott Babcock <email@hidden>
- Date: Wed, 2 Dec 2009 20:44:02 +0000
- Thread-topic: Snow Leopard osax security and 'run script' with parameters
Loaded script objects won't meet the objective to assemble script code on the fly, since these are static, pre-compiled scripts rather than being dynamically generated. Also, the re-worked script doesn't make use of the reference. It's merely a re-iteration of the first script with an extra unused parameter.
Run the original script again with event logging turned on. You'll see that the second 'run script' event is initially attempted in the context of "TextEdit" and gets killed with error -10004 (errAEPrivilegeError). The event is then re-tried in the context of the current application (AppleScript Editor) and fails to produce the desired result.
The issue here appears to be related to the way that object references get treated when they're specified as 'run script' parameters. Reference ownership appears to be handed off to the current context:
--------
tell application "TextEdit"
activate
set docRef to document 1
end tell
set theScript to "on run {X}" & return & "try" & return & "(X as record) as text" & return & "on error errmsg" & return & "return errmsg" & return & "end" & return & "end"
tell application "TextEdit" to run script theScript with parameters {docRef}
--------
You'll see that the 'from' component of the event record indicates that the reference is owned by the script, not TextEdit. However, even though the 'run script' event is not allowed to run within the context of TextEdit, the code won't run at all if you fail to 'tell' TextEdit (error -1700). The reference ownership can be restored within the script text by adding a 'tell' block:
--------
set theScript to "on run {X}" & return & "tell app \"TextEdit\"" & return & "try" & return & "(X as record) as text" & return & "on error errmsg" & return & "return errmsg" & return & "end" & return & "end" & return & "end"
tell application "TextEdit" to run script theScript with parameters {docRef}
--------
However, this repaired reference still doesn't connect with the expected object on Snow Leopard:
--------
set theScript to "on run {X}" & return & "tell app \"TextEdit\"" & return & "try" & return & "(X as record) as text" & return & "on error errmsg" & return & "tell X to set its text to errmsg" & return & "end" & return & "end" & return & "end"
tell application "TextEdit" to run script theScript with parameters {docRef}
--------
Instead of setting the text in the "Untitled" document of TextEdit, the text of the "Untitled" document of AppleScript Editor gets altered. This is especially odd, given that the text itself indicates the owner of the reference as TextEdit.
Ed Stockly wrote:
> Scott,
>
> I believe your parameters were being passed to the script, but the problem was something else.
>
> After a little tweaking I could get your script to work, but I think there is a better way.
>
> First, I wouldn't use a run handler, but would load your script as a script object.
>
> See the ASLG for more info and there's lots threads on Script Objects in the archives.
>
> HTH,
>
> ES
>
> -------
> tell application "TextEdit"
> activate
> set docRef to document 1
> end tell
>
> set theScript to "on run {X}" & return & "tell app \"TextEdit\" to set text of document 1 to X" & return & "end"
> run script theScript with parameters {"This is the simple test."}
>
> set theScript to "on run {X,y}" & return & "tell app \"TextEdit\" to set text of document 1 to X" & return & "end"
> tell application "TextEdit" to run script theScript with parameters {"This is the complex test.", docRef}
>
> On Dec 1, 2009, at 9:52pm, Scott Babcock wrote:
>
> >
> > tell application "TextEdit"
> > activate
> > set docRef to document 1
> > end tell
> >
> > set theScript to "on run {X}" & return & "tell app \"TextEdit\" to set text of document 1 to X" & return & "end"
> > run script theScript with parameters {"This is the simple test."}
> >
> > set theScript to "on run {Y, X}" & return & "tell Y to set its text to X" & return & "end"
> > tell application "TextEdit" to run script theScript with parameters {docRef, "This is the complex test."}
_______________________________________________
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