Questions tagged [javascript-automation]

an environment for scripting Mac applications using JavaScript. Available in OS X Yosemite and later, this is a newer companion to the traditional AppleScript environment, and targets the same underlying OSA object model. Sometimes abbreviated as JXA.

JavaScript for Automation is an environment for scripting Mac applications using JavaScript. Available for the first time in OS X Yosemite, this is a newer companion to the traditional AppleScript environment, and targets the same underlying OSA object model. JavaScript for Automation is sometimes abbreviated as JXA.

Apple's documentation as of this writing consists of release notes only, with the release notes for Yosemite describing the language features and providing examples on a single, lengthy page.

253 questions
2
votes
2 answers

Javascript for Automation custom URL in Yosemite

I'm trying to make a script, saved as an application bundle, that handle custom URL schemes. I know how to handle it in Applescript: on open location theURLtext do things here end open location But I don't know how to do it with javascript,…
2
votes
1 answer

JavaScript for Automation - Searching Calendar

In OSX Yosemite I am use the new JavaScript for Automation feature to script Calendar. I am attempting to search a Calendar to see if there is an event that is currently occurring. I have done this in AppleScript like so: set now to current…
2
votes
1 answer

Is there references of javascript GUI automation on yosemite(OS X 10.10)

I have installed os x 10.10 yosemite and I want to write a javascript to test an application automatically. Is there any javascript examples which I can references now?
user1287944
2
votes
1 answer

Can't convert types

I am following the WWDC talk Javascript for automation. Following is an example from slide 99. I am getting an error on line 3 on new install of yosemite. Safari = Application('Safari') doc = Safari.document[0] url = doc.url() // -> here doc.url =…
satyajit
  • 1,470
  • 3
  • 22
  • 43
1
vote
1 answer

Mac Automation - AppleScript, JavaScript for Automation (.JXA), and JavaScript (.JS)

I learned AppleScript last year and it's gone pretty well. After discovering BetterTouchTool, I learned about utilizing JXA or JS for automating tasks. I can make sense of the .jxa documentation on apple's Apple's JXA Release Notes I can also write…
1
vote
1 answer

Delete metadata descriptions with a Photoshop Script?

Is there an equivalent of deleteProperty(XMPConst.NS_DC, "description”) or some way to clear out EXIF:ImageDescription, XMP-dc:Description and IPTC:Caption-Abstract with a Photoshop Script (ie, JavaScript or AppleScript)? I am trying to remove the…
Chris
  • 35
  • 5
1
vote
1 answer

Copying rich text from the pasteboard into TextEdit: AppleScript works, but how to do this with JXA?

In a script, I need to put rich text from the pasteboard into TextEdit. This works as expected in AppleScript: tell application "TextEdit" activate set myrtf to the clipboard as «class RTF » set mydoc to make new document set text of…
Uli Zappe
  • 306
  • 3
  • 8
1
vote
0 answers

NodeJs: child_process.stdout, `data` be cut off

I am using NodeJs to run JXA (JavaScript for Automation). Below is my code: const spawn = require("child_process").spawn; const StringToStream = require('string-to-stream'); const code = ` ObjC.import('stdlib'); console.log('inited'); `; const…
1
vote
1 answer

How can I get an input folder and its files using Javacript for Automator?

I am writing an automator workflow to work with files and folders. I’m writing it in JavaScript as I’m more familiar with it. I would like to receive a folder, and get the folder’s name as well as the files inside. Here is roughly what I have…
Manngo
  • 14,066
  • 10
  • 88
  • 110
1
vote
1 answer

Get Id of Selected Apple Note in Applescript

I would like to get the id (or name) of the Apple Note (using the "notes" app on mac) that is currently in view (not a floated not, just the "selected" note), using either Applescript or JXA. Is that possible? I know how to get the id of the most…
SeanRtS
  • 1,005
  • 1
  • 13
  • 31
1
vote
1 answer

JXA 'Can't convert types'

JavaScript for Apple Numbers - I'm trying to use the row.address of a selected range to step through a for{} loop, but the values returned aren't compatible integers (if that makes sense). A spreadsheet is open, and several rows are selected when…
jbatl
  • 11
  • 1
1
vote
1 answer

Alert presented as sheet from JXA script never dismisses

I’m trying present an alert as a sheet using JXA. It works as expected in AppleScript, but when running the equivalent JavaScript the sheet never dismisses. To reproduce, run this in Automator with the “Run AppleScript” workflow: use framework…
1
vote
1 answer

How can we create a NSWindow in Javascript for automation (mac JXA)?

I would like to use JavaScript for automation (mac JXA) to make a NSWindow and show it to the user. I tried following this example, but it crashes when I run it in the Script Editor app. Then I tried to make my own using barebones. As a start I…
DerrickHo328
  • 4,664
  • 7
  • 29
  • 50
1
vote
1 answer

Writing non-ascii characters to xml/UTF-8

I have a script which assembles an xml document via string manipulation (which I wrote before I discovered the XML Suite). When certain characters are included such as £, –(en-dash) and —(em dash) (I suspect all non-ascii characters), they're…
1
vote
1 answer

JXA: get containers of an element

Using JavaScript for automation in macOS, it's straightforward to get the elements of a container. But I can't figure out how to get the containers of an element. In the Photos documentation, for example, an Album "contains mediaItems"; and a…
Dan Smith
  • 11
  • 1