• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Javascript for automation quastions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Javascript for automation quastions


  • Subject: Re: Javascript for automation quastions
  • From: David Steinberg <email@hidden>
  • Date: Thu, 11 Dec 2014 12:12:20 -0800

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

  • Follow-Ups:
    • Re: Javascript for automation quastions
      • From: Yvan KOENIG <email@hidden>
    • Re: Javascript for automation quastions
      • From: Deivy Petrescu <email@hidden>
References: 
 >Javascript for automation quastions (From: Deivy Petrescu <email@hidden>)

  • Prev by Date: Javascript for automation quastions
  • Next by Date: Re: Javascript for automation quastions
  • Previous by thread: Javascript for automation quastions
  • Next by thread: Re: Javascript for automation quastions
  • Index(es):
    • Date
    • Thread