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
0
votes
1 answer

Obtaining a list of class names with objc_getClassList in JavaScript for Automation

By using ObjC.bindFunction in JXA, we can obtain an integer result from objc_getClassList. Does anyone understand the types and bridging issues well enough to find a route to getting a list of class name strings returned by objc_getClassList into…
houthakker
  • 688
  • 5
  • 13
0
votes
1 answer

Process emails from mac using javascript (JXA) instead of applescript

I am trying to make an email parser in JXA. I was able to do something similar in applescript: tell application "Mail" to set theMessages to every message of mailbox "Inbox" of account "MyAcount" whose subject is equal to "Search Text" repeat with…
Ben Quan
  • 773
  • 11
  • 25
0
votes
1 answer

How to create a REST URL using json-server and use it in automation in vRO

I have added http://localhost:3000 as a part of "Add a REST host" workflow in vRO and this is successful but when I try to run "Invoke a REST host" it fails giving the error "cannot execute the request; connection refused". I am running json-server…
0
votes
1 answer

JXA: How to make a range in Numbers

I tried: table.selectionRange = table.ranges["C6:C7"]; Gets: Error -1728: Can't get object. I am able to use the table object: Eg: table.rowCount(); Any ideas? Note: Syntax 'table.selectionRange = table.ranges["C6:C7"];' was posted as a solution…
Crashmeister
  • 375
  • 1
  • 14
0
votes
1 answer

Why is JAX shell not seeing the command that is on the global path?

When I call my script that then calls my shell command I'm getting an error: Error: sh: excel: command not found I'm using the following code in my SCPT file: var app = Application.currentApplication(); app.includeStandardAdditions = true; var…
1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
0
votes
1 answer

Close modal message box with JXA

Writing JXA automation script that executes function of application. var app = Application('Pages') var doc = app.open(new Path('path to file')) app.export(doc, { to: new Path('path to file'), as: dstFormat, withParameters:…
Jonas
  • 4,683
  • 4
  • 45
  • 81
0
votes
1 answer

Send to Trash with JXA on Mac OS

So I have been looking for an answer to this and have had no luck. Is it possible to send a file to the trash using JXA in Mac Automation? my simple test code looks like this: // set startup applications that this script will use var app =…
0
votes
1 answer

Pages automation: You don’t have permission

I want to export "pages" file format to "pdf". My JXA script: function run(argv) { var pagesApp = Application('Pages'); try{ var doc = pagesApp.open('/Users/testas/Documents/test.pages') pagesApp.export(doc, {to:…
Jonas
  • 4,683
  • 4
  • 45
  • 81
0
votes
2 answers

Setting a BBEdit insertion point with JXA

I am trying to translate a few Applescript (AS) into Javascript (JXA) for BBedit. It's been a fun little thing to knock some rust off, but I'm stumped. With AS I can set an insertion point into a BBEdit document thusly; tell application "BBEdit" …
0
votes
1 answer

JXA .- How to open a mail based on ID in Outlook

I'm stumbling on a simple issue but cannot manage to wrap my head around and make it work. I'm trying using JAX to open a mail in Outlook based on it's ID. I know that with AppleScript it's dead easy: tell application "Microsoft Outlook" open…
sleeper
  • 518
  • 4
  • 9
0
votes
0 answers

JXA error with PDFDocument

I'm rewriting some python scripts into JXA, but having some difficulties. Here's the code: ObjC.import('Quartz') var pdfURL = $.NSURL.fileURLWithPath(filename) var pdfDoc = $.PDFDocument.alloc.initWithURL(pdfURL) var numberPages =…
benwiggy
  • 1,440
  • 17
  • 35
0
votes
1 answer

JXA: Number gets changed when passed as parameter to library module?

I am trying to pass a number (date in ms) to a function in a library module. The number gets screwed up! Here is a simple look (function MailUtils.showNum has only one line, the same log call as seen below): n = Number(todayMs -…
Crashmeister
  • 375
  • 1
  • 14
0
votes
1 answer

How to mount a volume and open a folder with Apple JXA

I'd like to mount a volume and then immediately open a Finder window to a specific path but I'm having trouble converting from Apple Script to JXA. I want the JXA equivalent of something like this: tell application "Finder" if not (disk "Airport…
Francisc0
  • 968
  • 1
  • 14
  • 28
0
votes
1 answer

How to create or edit Keynote master slides using JavaScript for automation?

I'm trying to automate the creation and inspection of master slides in Keynote using JavaScript for automation. Creating master slides It's easy to create a new document with a given theme and add slides with particular master slides to it. //…
TH.
  • 101
  • 4
0
votes
2 answers

JXA keystroke does not work with special characters

I'm trying to setup a simple Apple JXA script to write the well-known shrug emoji to screen (it simulates the key press I guess). Every thing I try produces this "¯\_(a)_/¯". I'm assuming since I'm using keystroke to simulate key press and I don't…
Francisc0
  • 968
  • 1
  • 14
  • 28