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

What is a more elegant way to overcome Error: Expecting object specifier. Argument has no object specifier when sending an SMS via Messages via JXA

This fails to work with (Application("Messages")) { send(text, {to: services["SMS"].buddies[phone]}) } with Error: Expecting object specifier. Argument has no object specifier. text is valid and not null. phone is…
Keith John Hutchison
  • 4,955
  • 11
  • 46
  • 64
1
vote
1 answer

Is there a better way to add a new playlist to iTunes through Javascript for Automation (JXA)?

There must be a better way to create a new element in a collection (if that's what really happens behind the abstraction). I'm looking for the JXA equivalent of this applescript if (count of (playlists whose name is plName)) is 0 then make new…
1
vote
2 answers

OS X Javascript Automation (JXA) Progress Bar

In an Applescript applet, progress can be shown like so: set progress description to "A simple progress indicator" set progress additional description to "Preparing…" set progress total steps to -1 delay 5 set progress total steps to 100 repeat…
Coder-256
  • 5,212
  • 2
  • 23
  • 51
1
vote
1 answer

Add track to iTunes playlist using JXA

I'm trying to build a simple JavaScript for Automation script to add the currently playing track in iTunes to a particular playlist. I have the playlist name stored as a string, var playlist. The JXA Library add method says the…
guyot
  • 364
  • 1
  • 9
1
vote
1 answer

javascript automation click download button in iTunes

I need to programatically download an app from iTunes using JXA. I've done the following: var its = SystemEvents.processes.byName('iTunes'); delay(3); its.windows[0].buttons.byName('Get').click(); There is no element selected. I've tried clicking…
1
vote
1 answer

Programmatically creating and populating a NSWindow using JXA

I've recently learned about the existence of JavaScript for Automation. More interesting to me is the ability to call into Objective-C APIs, subclass Objective-C classes in JavaScript, and the ability to pass objects of JavaScript-implemented…
1
vote
1 answer

WKNavigationDelegate using Objective-C Bridge (JXA)

I'm trying to create a WKNavigationDelegate for a WKWebView but have been unable to call the decisionHandler. Does anyone have any idea how to do this? ObjC.registerSubclass({ name: "test", methods: { …
qwe
  • 11
  • 3
1
vote
1 answer

JXA: How to get 2 terminal scripts to run in the same window

Why does this open two different windows and run each script in a different window? Is there a way to tell it to use the same window? var Terminal = Application('Terminal'); Terminal.activate(); var window =…
aks.
  • 386
  • 1
  • 12
1
vote
2 answers

Use Javascript for automation (JXA) to create a plist

I'm looking into creating a JXA to build a plist. My starting point is an AppleScript that I found here. I came up with this snippet: var se = Application('System Events'); var item1 = se.PropertyListItem({kind: "string", name: "employee_name",…
1
vote
1 answer

How can I get the frontmost Safari document or tab in JavaScript Automation?

I would like to access the frontmost tab being displayed in Safari and retrieve the URL using the JavaScript Automation scripting in Yosemite Script Editor. I can get the first window, first tab url using code…
1
vote
0 answers

How to register app launch listener in javascript for automation

I'm trying to build a script with javascript for automation to prevent certain applications from launching in OSX. In the documentation, there is a NSWorkspaceWillLaunchApplicationNotification notification. How can I listen for this notification,…
user2355213
  • 447
  • 4
  • 13
1
vote
1 answer

JXA get file's Size & checksum?

I am using JXA (javascript for automation) on my Mac to try to automate iTunes Connect screenshot uploads. Because of this, I want to automate grabbing each image and uploading it, but for iTunes Connect to allow this (using iTMSTransporter), I need…
1
vote
1 answer

How can I open new window of Safari by JavaScript Automation when Safari is running and has no windows?

When Safari is not running, I can open Safari by the following Automation JavaScript code. safari = Application('Safari') But when Safari is running and has no windows, the above code does not open Safari's new window. I tried to add the following…
Yuji
  • 614
  • 4
  • 18
1
vote
0 answers

Javascript for Automation not launching correct application

I'm trying to write an automation Javascript to test my app's AppleScript functionality. I want it to launch my dev build, so I started off like so: my_app =…
Dov
  • 15,530
  • 13
  • 76
  • 177
1
vote
3 answers

Pipe to subprocess stdin for JXA

I would like to start a subprocess in JavaScript for Automation (JXA) and send a string to that subprocess's stdin which might include newlines, shell metas, etc. Previous AppleScript approaches for this used bash's <<< operator, string…
Joe Hildebrand
  • 10,354
  • 2
  • 38
  • 48