applescript - Sending and receiving "raw" Apple Events from JavaScript on OS X (El Capitan) -
i trying make use of new javascript automation feature in os x (10.11) script application not offer dictionary. have applescript interacts application using raw apple events, so:
tell application "bookends" return «event toyssqls» "authors regex 'johnson' " end tell
now question is: how translate javascript? cannot find information on javascript osa api send , receive raw apple events.
one possible workaround might call piece of applescript through shell, prefer work "real" api.
you can @ least faster shell script call using osakit in couple of helper functions:
// evalosa :: string -> string -> io string function evalosa(strlang, strcode) { var oscript = ($.osascript || ( objc.import('osakit'), $.osascript)) .alloc.initwithsourcelanguage( strcode, $.osalanguage.languageforname(strlang) ), error = $(), blncompiled = oscript.compileandreturnerror(error), odesc = blncompiled ? ( oscript.executeandreturnerror(error) ) : undefined; return odesc ? ( odesc.stringvalue.js ) : error.js.nslocalizeddescription.js; } // eventcode :: string -> string function eventcode(strcode) { return 'tell application "bookends" «event toys' + strcode + '»'; }
which allow write functions like:
// sqlmatchids :: string -> [string] function sqlmatchids(strclause) { // select clause without leading select keyword var strresult = evalosa( '', eventcode('sqls') + ' "' + strclause + '"' ); return strresult.indexof('\r') !== -1 ? ( strresult.split('\r') ) : (strresult ? [strresult] : []); }
and calls like
sqlmatchids("authors '%harrington%'")
fuller set of examples here: javascript wrappers bookends functions
Comments
Post a Comment