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

Javascript Things3 on macOS Error: Can't convert types

I'm trying to implement automation for the task manager Things 3 on macOS using JXA (Javascript for macOS automation) and I'm running it to another strange error similar and related to Javascript macOS Error: Named parameters must be passed as an…
2
votes
1 answer

Javascript macOS Error: Named parameters must be passed as an object

I'm trying to implement automation for the task manager Things 3 on macOS using JXA (Javascript for macOS automation) and I'm running it to a strange error. I have spent countless hours trying to fix this myself and with the help of others. I am…
2
votes
1 answer

JavaScript for Automation - how to get the path of the current script?

In macOS' JavaScript for Automation (JXA), how to get the path to its own script? That is, the equivalent of the following AppleScript snippet path to me I've tried the following JavaScript snippet, but the resulting path points to the Script…
adib
  • 8,285
  • 6
  • 52
  • 91
2
votes
0 answers

Debugging JXA in VS Code

I'm trying to debug some JXA code in vs-code. I'm using @jxa/run and ts-node import "@jxa/global-type"; import { run as runJXA } from "@jxa/run"; async function run() { console.log('I can put a breakpoint here! :) '); return await…
parliament
  • 21,544
  • 38
  • 148
  • 238
2
votes
1 answer

Overcome the lack of JXA documentation by being able to explore the variables in a debugger

The documentation for JXA is lacking, so it would be extremely useful to be able to see the methods, variables, signatures, etc of the elements we deal with in the code. Unfortunately I haven't found a way to do this. Given a JS variable, arising…
Nisba
  • 3,210
  • 2
  • 27
  • 46
2
votes
1 answer

How to access text in UI element with JXA?

When you open a Terminal or iTerm window, you are shown a string like Last login: Fri Jul 10 00:00:00 on ttys000 (base) my_username@my_hostname ~ % I would like to be able to read this string into a variable in JXA. This is how far I got until…
Nisba
  • 3,210
  • 2
  • 27
  • 46
2
votes
2 answers

How can an image be saved with JavaScript for Automator (JXA) in macOS Preview application?

There is an image open in the Preview application, and it is unsaved. I have tried this code, by building and running a standalone script in Script Editor: var preview = Application('Preview') var preview.documents[0].close({ saving: true, savingIn:…
sealocal
  • 10,897
  • 3
  • 37
  • 50
2
votes
1 answer

Accumulate all JS warnings and errors during test runs in TestCafe

I would like to be able to access all JS warnings and errors from the Browser Console during test runs. With the "-e" (skip JS errors) flag disabled, the test stops at the first error, so clearly it is looking for them. With this flag enabled, I…
2
votes
1 answer

Trigger a script (AppleScript or JXA) on .app running?

I have a small computer lab for students to use fairly unsupervised, with a printer attached on the network. I am trying to implement a simple scripting additions alert dialog with all the rules about the printer that I need to pop up when they…
2
votes
3 answers

Accessing properties of object using JXA

I'm trying to access the properties of an object in an app called Papers3 using JXA. I'm new to JXA and this is proving challenging, especially because of the lack of documentation. Here is a shot of the dictionary for the object I'm trying to look…
Alex
  • 779
  • 2
  • 7
  • 20
2
votes
1 answer

How to call a shell command from JavaScript JXA?

I have an AppleScript script that is calling a shell command that I want to convert to JavaScript (JXA) but I don't see the equivalent of do shell script. Here is the script using AppleScript: #!/usr/bin/osascript on run argv set…
1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
2
votes
2 answers

How do you run inline Applescript from a JXA/JavaScript for Automation script on macOS?

I have a script written in JavaScript which needs to run one small piece of AppleScript (to achieve some functionality I've been unable to implement due to a number of factors natively in JS). It should be able to take a single string argument, and…
2
votes
2 answers

Read a text file into an array with OS X Javascript

I'm really struggling to find documentation on how to read a text file into an array using OS X Automation with Javascript. Here's what I have so far: var app = Application.currentApplication(); app.includeStandardAdditions = true; var myFile =…
Andy Cairns
  • 21
  • 1
  • 4
2
votes
1 answer

Bring window of process to the front?

This should be a simple enough question to answer (I assume). Say I want to activate window 1 of process "ScreenFlow", how would I do this? I do know that Application('ScreenFlow').activate() brings Processes['ScreenFlow').windows[0] to the front.…
Sancarn
  • 2,575
  • 20
  • 45
2
votes
1 answer

JXA/Applescript + Pages: Create Document from template

I'm trying to create a Pages file from a Template in JXA. I've successfully got this working in Applescript but am unable to understand the conversion to JXA. tell application "Pages" activate set thisDocument to ¬ make new…
Benno
  • 968
  • 6
  • 15