javascript-automation

Possible to execute inline JavaScript statement in Applescript?

别来无恙 提交于 2020-01-03 04:38:44
问题 I know that you can tell Chrome or Safari to do JavaScript (or write entirely in JS... à la JXA) but whilst answering another question, I got curious... Is there a way to arbitrarily execute an inline JavaScript statement inside an AppleScript (without tell ing another process)? So far I've only used something like this (in an AppleScript): do shell script "osascript -l JavaScript -e '\"" & myVar & "\".trim()'" But that seems such a silly workaround 回答1: If you want to write JavaScript, then

Can't find JXA documentation

泪湿孤枕 提交于 2019-12-23 17:37:53
问题 where can I find JXA documentation with all available classes, functions and parameters? After so far found just random code samples and short tutorials. 回答1: The most official source of documentation is the release notes: https://developer.apple.com/library/content/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/Introduction.html The WWDC 2014 presentation is also an authoritative source of information: https://developer.apple.com/videos/play/wwdc2014/306 回答2:

javascript for automation [open location in finder]

血红的双手。 提交于 2019-12-22 09:26:07
问题 I am trying to figure out how JXA(JavaScript for Automation) works, so try to translate a simple applescript as below to JXA. tell application "Finder" open location "smb://XXXXXXXX" end tell what I tried is here: finder = Application("Finder") finder.open({location:"smb://xxxxxx"}) but I fail..., and I am new to applescript, not really understand the description in library. and here is how the library describe the open open (v) : Open the specified object(s) open specifier : list of objects

JXA: Accessing CFString constants from CoreServices

廉价感情. 提交于 2019-12-21 20:18:28
问题 JXA, with its built-in ObjC bridge, exposes enumeration and constants from the Foundation framework automatically via the $ object; e.g.: $.NSUTF8StringEncoding // -> 4 However, there are also useful CFString constants in lower-level APIs that aren't automatically imported, namely the kUTType* constants in CoreServices that define frequently-used UTI values, such as kUTTypeHTML for UTI "public.html" . While you can import them with ObjC.import('CoreServices') , their string value isn't

How to get POSIX path of the current script's folder in JavaScript for Automation?

心不动则不痛 提交于 2019-12-18 05:05:16
问题 In AppleScript it’s possible to get the the POSIX path of the folder the current script is located in using this line: POSIX path of ((path to me as text) & "::") Example result: /Users/aaron/Git/test/ What’s the JavaScript equivalent? 回答1: Here's a way [NOTE: I NO LONGER RECOMMEND THIS METHOD. SEE EDIT, BELOW] : app = Application.currentApplication(); app.includeStandardAdditions = true; path = app.pathTo(this); app.doShellScript('dirname \'' + path + '\'') + '/'; note the single quotes

OS X Yosemite Javascript for Automation and iTunes

梦想的初衷 提交于 2019-12-13 21:30:34
问题 I'm trying to click on button "Free" to download application in iTunes. I'm using Javascript for Automation to open iTunes application page: itunes = Application('iTunes'); itunes.activate(); console.log( itunes.name() ); console.log( itunes.version() ); delay(1) appUrl = "itms://itunes.apple.com/us/app/ibooks/id364709193?mt=8"; win = itunes.openLocation(appUrl); The script opens iBook page. How to find and click button "Free"? How to list all elements on open page? Thank you for any help.

Mail Rules with javascript instead of applescript

谁都会走 提交于 2019-12-13 01:45:05
问题 In a Mac mail rule, I am trying to run a javascript instead of an applescript. This has been asked in Mail Rules using JavaScript for Automation instead of AppleScript but the answer is not working for me! I have tried to simplify the code as much as I can. So, the following applescript works fine: on perform mail action with messages theMessages say "running!" end perform mail action with messages but the equivalent javascript is not working. function performMailActionWithMessages(messages)

How to make a range in Numbers (iWork) using JXA

。_饼干妹妹 提交于 2019-12-12 13:15:07
问题 I'm using JXA for automating a process using Numbers app. What I need is to select a range of cells to apply width, but JXA doesn't allow me to get them. According to apple documentation I only need to use make or push the created object inside of array, but any ones work. This is my code and the Automator error: Option 1: var Numbers = Application('Numbers'); Numbers.Range({name: 'A2:A20'}).make(); // -> Error: Can't make or move that element into that container Option 2: var Numbers =

Extract PresentationNotes from keynote

故事扮演 提交于 2019-12-11 20:36:01
问题 I'm having a hard time extracting presentationNotes from a keynote presentation using JXA (Javascript for osx) I don't want to use applescript. There is way more to this script than extracting notes. It seems rather simple. However when I get the presentationNotes its in an RichText object that doesn't seem to have anyway to get normal text. So I figured I'd open up textEditor and write them out to it. Well I can't figure out how to do that. var app = Application('Keynote') document = app

How can I find out all the methods on a JXA object?

故事扮演 提交于 2019-12-10 13:35:58
问题 I'm trying to list all the methods of a JXA object. I've tried several methods that work with JavaScript in the browser, but none have worked: >> Object.getOwnPropertyNames(Application('Finder').selection()[0]); => ["__private__"] >> >> JSON.stringify(Application('Finder').selection()[0]) => undefined >> >> console.dir(Application('Finder').selection()[0]) !! Error on line 1: TypeError: console.dir is not a function. (In 'console.dir(Application('Finder').selection()[0])', 'console.dir' is