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
3
votes
0 answers

Equivalent of Applescript's "with timeout" in Javascript for macOS automation

I'm trying to copy values from one Excel sheet to another using Javascript in macOS automation. It's all ok until the number of values to copy gets rather big (like 500k) — the script hits the time limit and returns an "AppleEvent timed out"…
a-change
  • 656
  • 5
  • 12
3
votes
1 answer

Comparisons / Rich queries in Javascript for Automation (JXA) "whose()"

If I wanted to look through my OS X Calendar (formerly "iCal") to find events whose summary was "Lunch", I could do something like this: var eventsContainer = Application('Calendar').calendars[0].events for (var i = 0; i < eventsContainer.length;…
3
votes
1 answer

How do I work with POSIX paths in JXA

In AppleScript I often need to convert between files as POSIX paths and as AppleScript’s native file aliases. The way to do it is via the POSIX File class in standard additions: set aFile to POSIX file "/" get aFile's POSIX path How do I do these…
Raphael Schweikert
  • 18,244
  • 6
  • 55
  • 75
3
votes
1 answer

Sending and receiving "raw" Apple Events from JavaScript on OS X (El Capitan)

I am trying to make use of the new JavaScript Automation feature in OS X (10.11) to script an application that does not offer a dictionary. I have an AppleScript that interacts with that application using raw Apple Events, like so: tell application…
3
votes
2 answers

JXA Move a message to a different folder/mailbox

I'm stuck writing a JXA script using Apple's Script Editor. Essentially, I want to go through my inbox folder and move messages older than 44 days to an archive folder. I'm able to find the account, and my inbox and archive "mailboxes", but I…
madsteer
  • 71
  • 6
3
votes
1 answer

JXA Equivalent of With Administrator Privileges

In AppleScript, you can do: do shell script "echo 'I am (G)root'" with administrator privileges Sorry. Anyway, a shell script can be run in JXA like this: var app = Application.currentApplication(); app.includeStandardAdditions =…
Coder-256
  • 5,212
  • 2
  • 23
  • 51
3
votes
2 answers

What clipboard type class strings does OS X JavaScript for Applications recognise?

The StandardAdditions.sdef indicates that particular data types can be retrieved from the clipboard using the key 'as'. The clipboardInfo() function reveals what these keys are for Applescript, but is less eloquent in case of Yosemite JavaScript.…
houthakker
  • 688
  • 5
  • 13
3
votes
1 answer

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

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…
3
votes
2 answers

Mac OS X Javascript for Automation displayDialog

I'm trying to get a simple dialog to show for a workflow I'm working on, but using JXA I keep getting the error: Expecting object specifier, argument has no object specifier. I don't know what to pass in for the object Specifier. My code is below,…
richbai90
  • 4,994
  • 4
  • 50
  • 85
3
votes
1 answer

How do you start an application in JavaScript via 'osascript'?

How do you start an application in JavaScript via osascript? I have been playing around with some of the examples, which can be found on the Internet and I can get them to work, but if an application targeted for automation is not already started I…
jonasbn
  • 183
  • 4
  • 11
3
votes
0 answers

Opening FileName:LineNumber in Xcode from AppCode

I want switch from AppCode to Xcode and continue editing file on the same line. Solution based on UI Automation seems working. Is the are any solution how to do the same without UI Automation; without need of showing Open Quickly dialog and typing…
Vlad
  • 6,402
  • 1
  • 60
  • 74
3
votes
3 answers

Sending iMessage via Messages.app using Javascript for Automation (JXA)

I have been attempting to create a JavaScript for Automation script to send an iMessage via the Messages app on Yosemite 10.10.2 (the end goal to write a solution to allow backoffice tasks to iMessage failure statuses etc.). The script executes…
Bugmeister
  • 73
  • 1
  • 7
3
votes
1 answer

javascript for automation [open location in finder]

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 =…
Cyrus Ngan
  • 199
  • 1
  • 6
2
votes
1 answer

Load script library in JXA (AppleScript JS)

I've created a custom .scpt file with some library functions and want to load that library in my other scripts. I've followed the official guide by Apple, and here is what I've got: A) Test with AppleScript Library File: ~/Library/Script…
Philipp
  • 10,240
  • 8
  • 59
  • 71
2
votes
0 answers

Populating images on a Keynote file using Javascript for Automation (JXA)

I would like to populate a keynote presentation with images that I have stored in my home directory. Each image should go to one slide. I've looked a lot on the internet but I've only an example which doesn't work for me. let app =…
1 2
3
16 17