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

AppleScript value for AXURL fails with AppleEvent handler failed

I have been trying to capture a URL in Apple Music (formally iTunes) using AppleScript (JXA JavaScript) but unfortunately when returning the value for an AXURL attribute the program. Am I missing something on converting this URL to something useful…
kylewelsby
  • 4,031
  • 2
  • 29
  • 35
0
votes
2 answers

How to replace placeholderTexts in Pages (iWork) using JXA?

I'm converting AppleScript code to JXA and I'm stuck because I can't figure out how to replace placeholderTexts. I tried to replace whose with where but no success. Here's the code: var PagesApp = Application("Pages"); var theseTags =…
wchongo
  • 31
  • 4
0
votes
1 answer

How to count the number of objects created in Javascript?

I am working in JXA and trying to count the number of events in a calendar. As far as I understand each event in a calendar is an object, in the class calendar. The example code places the objects in an array and then counts the length of the…
OrigamiEye
  • 864
  • 1
  • 12
  • 31
0
votes
1 answer

Get stdout from application without completion

I have this game I run with shell script. When the game is running through terminal, it actively prints informations like "Connected to Server" or "Disconnected" and so on. const app = Application.currentApplication() app.includeStandardAdditions =…
0
votes
2 answers

How to copy image or file to clipboard using JXA?

I have difficulty using JavaScript in ScriptEditor AppleScript copy image to clipboard by path like this set image to POSIX file ("/Users/lll00lll/Library/Documents/temp.jpg") set the clipboard to image But how to translate above AppleScript code…
0
votes
0 answers

How to get the scrollArea position and size of Chrome/Safari using AppleScript on MacOS?

I would like to retrieve the scrollArea size and position of Google Chrome using AppleScript (JXA). (my goal is to get the client area size). I am unable to find the corresponding UIElement inside the hierarchy. Here is the JXA code: function…
JCB
  • 116
  • 1
  • 4
0
votes
1 answer

Cypress form submit to same url

I am testing a form submit with Cypress. My Form action is the same has the current page URL. Once I hit submit it downloads a file. I am facing two issues: Since my form action URL is the same as the current page URL, after submitting it went on…
0
votes
1 answer

How can I switch sheet focus in Numbers using JXA?

I am working on a JXA script that will be used to copy tables from an existing Numbers sheet, and then paste them into a newly created sheet (in the same document) before making some modifications to individual cell values. I have most of what I…
0
votes
2 answers

Get the list of all running fullscreen apps (or spaces) using JXA

Given there are apps running in fullscreen mode, I'm wondering if there's a way to list them using JXA. Something similar to below but for all running fullscreen apps. var list = Application('System Events').applicationProcesses.where({…
Chanaka
  • 954
  • 1
  • 8
  • 17
0
votes
2 answers

How to check if process is already running by name in JXA

Using /usr/bin/osascript JS to automate my task, struggling with a check if process is already running or not: const app = Application.currentApplication() app.includeStandardAdditions = true function run(args) { const query = args[0] let…
Alexander Kim
  • 17,304
  • 23
  • 100
  • 157
0
votes
3 answers

Problem assigning 'doJavaScript' return value to a variable (array)

I'm experimenting with JXA and trying to 'port' a small script, which parses track names from the web page. This script is currently working as Keyboard Maestro macro and is executed in current Safari window: var trackBlock =…
0
votes
0 answers

How Do I Use Objective-C (ObjC) with JavaScript for Automation (JXA) to create HTTP request?

I created a simple http request in the following way: source: Getting HTML Source from a URL without a Web Browser var urlStr = "https://stackoverflow.com/"; var htmlStr = getHTMLSource(urlStr); htmlStr.substring(0,200); function…
0
votes
1 answer

JXA for automation: url encoding for get request

I am trying to send a text via get request to my server, but I have some struggles with spaces/special characters. How can I encode my text for the request? (And how to decode it in php?) Here is my code: var app =…
maxischl
  • 579
  • 1
  • 11
  • 29
0
votes
1 answer

How do I get to see the contents of a NSData array in JXA?

I need to do some manipulation on a file byte array and as far as I have read, I cannot do this unless I use ObjectiveC bridging. This is what I have done for now: var filepath =…
0
votes
0 answers

JXA: Drop folder, create new folder, move matching files into new folder

I'm VERY new to JXA, so I'm sure there's a lot I don't know yet. I'm a Javascript developer, but have only been researching this for a day. Here's what I'm trying to do: I have a ton of folders on my MacBookPro with video courses in them, in mp4…
Eddie
  • 1,228
  • 3
  • 17
  • 31