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

AppleScript Fastest Way to Get Selected Rows From a Large Table?

I have a large table with about 1000 rows. If I try to get selected rows from the table, it takes more than 30 seconds. Is there way to speed up the process? I use JXA. selected = table.rows.whose({selected:true})() names = "" for (r in selected) { …
chibop
  • 119
  • 9
2
votes
2 answers

Application.make in JavaScript for Automation (JXA)

I'm trying to convert this existing AppleScript script: tell application "System Events" make login item with properties {path:"/Applications/Application.app", hidden:false"} end tell return Here is what I have so far: #!/usr/bin/env osascript -l…
reitermarkus
  • 678
  • 1
  • 11
  • 27
2
votes
1 answer

Selecting a popup menu with javascript applescript

I have a AXPopUpButton that brings up a contectual menu if you click it. However, I can't seem to access the menu with javascript applescript UIAutomation. pop = item.popUpButtons.byName("Select") pop.click() delay(0.5) Then the menu shows up on…
2
votes
1 answer

JXA NSFileManager createDirectoryAtPathWithIntermediateDirectoriesAttributesError exception

I'm using the following JXA (JavaScript for Automation) code on OS/X 10.11.5: function createFolder(path, createIntermediateDirectories) { var error = {} $.NSFileManager.defaultManager …
Dan Thomas
  • 55
  • 1
  • 6
2
votes
2 answers

Applescript Filtering Arrays using whose ObjectSpecifier using Javascript

`The Javascript Automation release note by Apple has an example for searching an array with arbitrary objectSpecifier. firstTabsName = ObjectSpecifier.tabs[0].name app.windows.whose({_match: [firstTabsName, 'Apple']}) However, the first lines…
jl303
  • 1,461
  • 15
  • 27
2
votes
3 answers

How to close all Finder windows using JXA

I basically want to port this code from AS to JXA: tell application "Finder" close every window open folder "Projects" of folder "Documents" of home tell the front Finder window set the bounds to {0, 0, 1920, 1080} set…
Reydel Leon
  • 1,035
  • 2
  • 11
  • 34
2
votes
1 answer

How can we reading / coerce CFArray and CFString etc values from within OS X JXA?

If you experiment with reading/setting the OSX input language through the ObjC bridge, writing snippets like: (function () { 'use strict'; ObjC.import('Carbon'); ObjC.import('stdio'); var sourceList =…
houthakker
  • 688
  • 5
  • 13
2
votes
2 answers

Sending System Events key down/up using JXA

I have been trying to figure this out for a while now and was wondering if you could help. With AppleScript, there are two hidden functions available in the System Events application which allow you to push a key down (keeping it down while other…
Fotis Gimian
  • 538
  • 5
  • 13
2
votes
1 answer

How to define a persistent property in JXA

In AppleScript I would write property foo: "value" and the value would be saved between runs. How can I do this in Javascript for Automation?
Daniel Schlaug
  • 1,504
  • 1
  • 13
  • 17
2
votes
4 answers

How can one address two instances of the same application through osascript

Can anyone think of a workaround for the osascript index-by-name bottle-neck in its reference to multiple instances of the same application ? If we obtain two process ids – one for each of two different instances of the same application, osascript…
2
votes
3 answers

JXA: move or duplicate files

I’m trying to do a very simple thing — move (or duplicate) a file using JavaScript for Automation introduced with OS X Yosemite. So far I have something like this. finder = Application("Finder") finder.move(Path("/Users/user/Source/file.pdf"), { …
user3359826
2
votes
3 answers

How to click UI element using JXA

Please tell me how do I click in point coordinates in application window? I trying to UI automate my application on OSX 10.10 using JXA technology. In documentation I found that it's possible using click at event. By I'am beginner of JXA and cant…
toohtik
  • 1,892
  • 11
  • 27
2
votes
1 answer

Error when using Application.currentApplication() in JavaScript for Automation (OSA)

When using Application.currentApplication() in an OSA script, it issues the following warning when running it from the command line: warning: failed to get scripting definition from /usr/bin/osascript; it may not be scriptable. Why is this…
aaronk6
  • 2,701
  • 1
  • 19
  • 28
2
votes
1 answer

Send Mac OS X Notification Center message via JavaScript - 10.10 Yosemite

How can a message be sent to the Mac OS X Notification Center using the JavaScript for Automation functionality that was introduced in 10.10 Yosemite?
2
votes
2 answers

How can I open a new Chrome window with javascript automation in yosemite?

I'm trying to do something basic. I just want to open a new window and then in that window, open 2 tabs, using OSX Yosemite's new javascript bridge. I can't find docs that show how to do this: ObjC.import("Cocoa"); chrome = Application("Google…
jas
  • 580
  • 1
  • 7
  • 18