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
1
vote
1 answer

Acitvate a given window in a multi-window application with JXA

Suppose I have two open TextEdit files, and consequently two windows. How can I switch/activate windows programmatically with JXA? At the moment I have this: var text = Application("textEdit") text.activate() var file1_path =…
Ferex
  • 553
  • 6
  • 22
1
vote
0 answers

Calling an application by the bundle signature using JXA (macOS)

When calling an application using JXA (JavaScript for automation), you can refer to the app by the bundle name or by the identifier, just like in AppleScript: tell application "TextEdit" to activate tell application id "com.apple.TextEdit" to…
1
vote
1 answer

How to get multiple properties from objects in JXA?

Is there a way in JXA to get multiple properties from multiple objects with a single call? For example, I want to get name and enabled property from menu items which can be done for each individual property as follows: Application("System…
Vader
  • 3,675
  • 23
  • 40
1
vote
1 answer

What is r/o in AppleScript documentation?

In AppleScript documentation, some parameters have r/o marked. What is it? name (text, r/o) : Its name.
John Doe
  • 2,225
  • 6
  • 16
  • 44
1
vote
1 answer

How do I write a LZ compressed string to text file using JXA?

I am trying to write a JXA script in Apple Script Editor, that compresses a string using the LZ algorithm and writes it to a text (JSON) file: var story = "Once upon a time in Silicon Valley..." var storyC = LZString.compress(story) var…
PE B
  • 65
  • 4
1
vote
1 answer

How to Launch Asynchronous Background Process in JXA

I'm trying to get an HTTP server running from a JXA (JavaScript for Automation) Mac app. This part is easy as easy as: app.doShellScript("python -m SimpleHTTPServer"); (More info here:…
Paul Gordon
  • 2,532
  • 3
  • 26
  • 24
1
vote
1 answer

Getting values from inner functions of current webpage in Chrome via (JXA / AppleScript)

I can't get values from inner functions of current webpage in Chrome. Why it's happened? for examples in JXA: function getTime() { const chrome = Application('Google Chrome') const currentTab = chrome.windows[0].activeTab() return…
1
vote
1 answer

Why are some returned arrays limited in JXA (Javascript for Automation in macOS)

I try to get all my iMessage contacts from the app "Messages" via JXA scripting. When I assign the array to a variable I can only work with the first 40 objects. But the array has a length of 147. var Messages = Application("Messages") var buddies =…
Vlorian
  • 89
  • 10
1
vote
1 answer

Adding email to new contact with JXA

I'm trying to create a contact using Javascript for Automation (JXA) but I haven't been able to figure out how to add an email address to the contact. This is the code for adding the contact: Contacts = Application('Contacts') person =…
Tom Borowski
  • 683
  • 1
  • 5
  • 7
1
vote
0 answers

How to Export Movies in QuickTime Player using JXA?

I can start and stop a recording in QuickTime Player 10.5 using JXA, but I'm having a problem exporting. qt = Application("QuickTime Player") movie = qt.newMovieRecording() qt.start(movie) delay(3) qt.stop(movie) qt.export(movie,…
jl303
  • 1,461
  • 15
  • 27
1
vote
2 answers

osascript is very slower than Script Editor

First of all, I admit that I'm starting with a new project with JXA (Javascript automation for mac os) without having much understanding about AppleScript. Currently, I'm trying to run following command using JXA: Application("System…
Hungry Mind
  • 113
  • 7
1
vote
1 answer

How to add AppleScript/JXA support to non cocoa app?

I'm looking into things I can contribute to open source. One pain point I have with many FOSS apps I use is they don't support scripting. I'm thinking it would be nice to at least try to add some basic scripting support to some of the apps I use,…
PopKernel
  • 4,110
  • 5
  • 29
  • 51
1
vote
1 answer

Mail Rules with javascript instead of applescript

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…
Ben Quan
  • 773
  • 11
  • 25
1
vote
2 answers

Reading a large batch of objects taking way too long

I’m experimenting with scripting a batch of OmniFocus tasks in JXA and running into some big speed issues. I don't think the problem is specific to OmniFocus or JXA; rather I think this is a more general misunderstanding of how getting objects works…
zambezi
  • 1,505
  • 2
  • 11
  • 14
1
vote
1 answer

How to Access system info in JXA AppleScript?

In AppleScript, you can do something like: set username to short user name of (system info) set computername to host name of (system info) set ethernet to primary Ethernet address of (system info) set ipaddress to IPv4 address of (system info) set…
jl303
  • 1,461
  • 15
  • 27