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

OSX Yosemite - JavaScript for Automation Accessing Enums

I'm starting to try converting some of my AppleScripts into JavaScript in OS X Yosemite, but I don't understand how I'm supposed to access enums from applications. For example - the status of Adium. In AppleScript: tell application "Adium" if…
4
votes
0 answers

How to read notifications on MacOS

I'm trying to get a Python program to read Mac notifications. I’ve tried a few things including using Pync, then I took a look at JxA. But it seems (at least what I've seen) everything only helps with creating notifications, not reading them. Is…
user4367814
  • 551
  • 1
  • 6
  • 15
4
votes
0 answers

Convert AppleScript sdef to TypeScript .d.ts?

Most OS X applications (particularly the ones written by Apple) are scriptable using either AppleScript or JavaScript. The API each application supports is described by an SDEF file. (See e.g. sdef /Applications/Safari.app.) Is there any way to…
mjs
  • 63,493
  • 27
  • 91
  • 122
4
votes
1 answer

Applescript Iterate UIElements using Javascript

Could someone please help me to make a script that reports all the children and its properties of an uielement? It's similar to entireContents() function. Here's my recursive function. function iterate(obj) { for (var property in obj) { …
jl303
  • 1,461
  • 15
  • 27
4
votes
3 answers

setTimout with Javascript for automation

I have tried to use a window.setTimeout but I get an error at runtime: Error on line 182: TypeError: window.setTimeout is not a function. (In window.setTimeout(function(){ }, 3000); ,window.setTimeout is undefined) (-2700) Can someone help me ?
Mermoz
  • 51
  • 1
  • 4
4
votes
0 answers

JXA Creating an app delegate causes app to crash

I'm trying to create a dock menu for a small application written using JavaScript for Automation. Here's a stripped down version of the code I'm using: ObjC.import("Cocoa"); // Create the menu var menu = $.NSMenu.alloc.initWithTitle('Menu'); var…
4
votes
2 answers

Why won't OSA_LIBRARY_PATH not work as documented for JXA?

According to Apple's Developer Docs the Library global allows one to import compiled scripts so they can be used as a library in one's current script. This works just fine if you were to do something like the below code with myLibName.scpt located…
Mikis
  • 80
  • 2
  • 7
4
votes
1 answer

Using the `runScript` function to run a JXA script does not allow parameters

I use JXA to script workflows for Alfred 2 and recently tried to run a script from within another script. I need to pass some text between the scripts, so I decided to use parameters, but whenever I try to pass a string, a number, an array or…
Ontonator
  • 319
  • 3
  • 17
4
votes
3 answers

JXA: Accessing CFString constants from CoreServices

JXA, with its built-in ObjC bridge, exposes enumeration and constants from the Foundation framework automatically via the $ object; e.g.: $.NSUTF8StringEncoding // -> 4 However, there are also useful CFString constants in lower-level APIs that…
mklement0
  • 382,024
  • 64
  • 607
  • 775
4
votes
0 answers

Spotify property returns anonymous function

running the following code in Script Editor app = Application('Spotify'); app.soundVolume returns [function anonymous] { "name":"", "prototype":{"constructor":[function anonymous]} } instead of an integer value. If I try to run the function…
Yannick
  • 535
  • 4
  • 18
4
votes
1 answer

How to run JavaScript/AppleScript from cocoa app?

I am trying to execute some AppleScript from Objective-C using NSAppleScript... however, the code I am trying is the new JavaScript for automation in Yosemite. It does not appear to do anything when it is run, however, normal AppleScript works fine.…
3
votes
2 answers

Webdriver.IO[7] : SwitchToFrame with css selector is not working

I want to click web element inside the iframe and trying to switch to respective iframe before clicking to web element. browser.switchToFrame(number) - switch to iframe with number is working but unable switch to iframe with css selector. I have…
3
votes
1 answer

JXA iTerm Automation - Wait for command to finish

I'm trying to use JXA to automated iTerm. I want to compile some UI code in "watch mode" in the first tab. After the library is compiled the first time (and a dist/ folder is created), I want a second tab to open and run some other code which is…
parliament
  • 21,544
  • 38
  • 148
  • 238
3
votes
2 answers

Encode / Decode PNGs to base64 strings in JXA/JavaScript

I am trying to write a JXA script in Apple Script Editor that converts PNG files to base64 strings, which can then be added to a JSON object. I cannot seem to find a JXA method that works for doing the base64 encoding /decoding part. I came across a…
3
votes
1 answer

Launch a Mac application from a JavaScript for Automation (JXA) script

The AppleScript way to launch a Mac application is: tell application "iTunes" activate end tell What's the equivalent in JavaScript for Automation (JXA)?
Alan W. Smith
  • 24,647
  • 4
  • 70
  • 96
1
2
3
16 17