Re: Javascript for automation quastions
Re: Javascript for automation quastions
- Subject: Re: Javascript for automation quastions
- From: Deivy Petrescu <email@hidden>
- Date: Sat, 13 Dec 2014 07:49:08 -0500
David, thank you this was very helpful.
I wanted to know if I could run an AppleScript from within a JavaScript script.
I missed the dictionary explanation of the “in” part.
That is very cool. I can find a lot of use for that.
“this” as "me" never occurred to me, because "self" and “me” seems to point to the other direction….
But it was my disattention. It was clear it should be “this"
I am not a proficient Javascript scripter, I come from the AS side.
I read the release notes many times, actually it is constantly opened for me to consult it.
However, I never thought that that parameter type checking was supposed to be used in the particular case.
The dictionary is my bible and I don’t question it.
Now I (hope) I got it and I would know how to solve the problem, if it happens again, but it would be my suggestion that somehow this example could be incorporated in the release notes, I believe it would help AS scripters during the transition period.
Anyway, thank you so much. I am enjoying relearning AS.
> On Dec 11, 2014, at 15:12 , David Steinberg <email@hidden> wrote:
>
> Hi Deivy,
>
> pathTo can be called with the global object to get the path to the script.
>
> app = Application.currentApplication()
> app.includeStandardAdditions = true
>
> pathToScript = app.pathTo(this)
>
> As shown in the release notes, you can turn off parameter type checking to be able to send any kind of parameter to a method.
>
> app = Application.currentApplication()
> app.includeStandardAdditions = true
>
> // Turn off parameter type checking
> app.strictParameterType = false
>
> // Run script text
>
> scriptText = 'Application("Mail").activate()'
> app.runScript(scriptText, { in: 'JavaScript' })
>
> // Run a saved script
>
> // Build a path to a script using Standard Additions
> pathString = app.pathTo('desktop') + '/foo.scpt'
>
> // ...or build a path to a script using Objective-C
> pathString = $('~/Desktop/foo.scpt').stringByExpandingTildeInPath.js
>
> pathObject = Path(pathString)
>
> app.runScript(pathObject)
>
> I hope that helps!
>
> - David
>
>> On Dec 11, 2014, at 08:00, Deivy Petrescu <email@hidden> wrote:
>>
>> Some questions that I could not find the answer (plenty more to come).
>>
>> First, how does one get “me” in JSA ?
>>
>> Example:
>>
>> <script>
>> set k to path to me
>> </script>
>>
>>
>> Note: me points to <<scrpt>> not to the “front” document.
>>
>>
>>
>> Second, “runScript", according to the dictionary it takes text:
>> "run script script : the script text (or an alias or file reference to a script file) to run”
>>
>> In AppleScript the following works:
>>
>> <script>
>> run script "Tell app \"Mail\" to activate”
>> </script>
>>
>>
>> In JSX the following does not work
>>
>> <script>
>> se = Application.currentApplication()
>> se.includeStandardAdditions = true
>>
>> scrpt= "Application('Mail').activate()"
>>
>> se.runScript(scrpt)
>> </script>
>>
>> ——>Error:"Error on line 6: Error: Expected script but found string.”
>>
>> However if I try the following works, but it throws an error
>>
>> <script>
>> se = Application.currentApplication()
>> se.includeStandardAdditions = true
>>
>>
>> se.runScript(Application('Mail').activate())
>> </script>
>>
>> —>Error: "Error on line 5: Error: Expected script but found boolean.”
>>
>> In both JSA scripts the error line is the last line
>> Is this an error on the JSA dictionary?
>>
>> What is the point of JSA taking a script instead of text?
>> If you put the script into a variable it will execute before the call to runScript.
>>
>> Thanks
>>
>>
>> Deivy Petrescu
>> email@hidden
_______________________________________________
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