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

how to add a group to adress book app with javascript on mac os

I try to import csv file in my contacts in a new group with javascript or applescript (I will appreciate help in JS). what I've tried:(I tried lot combinaison of this command) var contact = Application("Contacts"); var group =…
1
vote
1 answer

Clicking UI element with JXA doesn't work

I'm trying to interact with the default Mail app using Javascript for Automation (JXA). I want to click on the first email in the list so that it opens in its own window. but clicking does nothing. The solution suggested here is what I tried and it…
1
vote
1 answer

JXA: Create a mailbox in Apple Mail

I am trying to create a sub-mailbox in Apple Mail using JavaScript. I have the following code snippet (parent is a reference to the mailbox in which I want the new mailbox): var mb = mail.Mailbox({name: "SubFolder"}); parent.mailboxes.push(mb); The…
Crashmeister
  • 375
  • 1
  • 14
1
vote
1 answer

jxa - Getting NSAttributedString font metrics in JavaScript for Automation

In macOS Sierra JavaScript for Automation, we can write: // helvetica12Width :: String -> Num function helvetica12Width(str) { return $.NSAttributedString.alloc.init.initWithString( str ) .size.width; } to get…
houthakker
  • 688
  • 5
  • 13
1
vote
1 answer

Triggering scripts on system events in Unix / macOS

Is there a way to trigger scripts according to specific system events on Unix / Linux / macOS? Examples may be beforeSleep, beforeLogout, afterVolumeChange and the like. I would like to write a script in javascript / jxa that gets executed just…
jonas-schulze
  • 238
  • 1
  • 13
1
vote
1 answer

How can I get the posix path of a file that is selected by Finder?

I am trying to get the full path of a file that is selected by Finder. At this point, I have tried many methods: >> Application('Finder').selection()[0] =>…
stiemannkj1
  • 4,418
  • 3
  • 25
  • 45
1
vote
0 answers

Is it possible to make an asynchronous call in JXA Objective-C bridge

I'm trying to use Objective-C Bridge in a Javascript for Automation script to access the Event Store. Here's my code: ObjC.import('EventKit'); var store = $.EKEventStore.alloc.initWithAccessToEntityTypes($.EKEntityMaskReminder); var predicate =…
Jack James
  • 5,252
  • 6
  • 36
  • 38
1
vote
0 answers

Automating OSX with Folder action: AppleScript works, JXA script fails?

I use Folder Actions Setup to attach this script to a folder. I either remark out the AppleScript portion or the JXA function to run one or the other and change Script Editor to match the language. Here is the AppleScript version: on adding folder…
Buoy
  • 795
  • 1
  • 8
  • 13
1
vote
2 answers

Can you write folder actions with javascript (jxa)?

I am looking for a direct translation of AppleScript's on adding folder items to this_folder but I can't seem to find it anywhere, neither the usage of the terms or the keyword this_folder itself.
KalanyuZ
  • 672
  • 6
  • 15
1
vote
2 answers

How to access Chrome active tab URL using Script Editor and JavaScript

I'm trying to write my first OS X script using JavaScript instead of AppleScript, and am running into some issues. The first part of this is to get the URL from a tab in Chrome, so that I can do some more work on it (e.g., create a new reading list…
1
vote
0 answers

JXA Delete Old Messages in Apple Mail

I asked this question a few months ago. @foo and @bacongravy posted some comments below my solution that I found interesting. Rather than continue those comments (wouldn't fit in the text limit of a comment), I thought I'd ask a new, but similar,…
madsteer
  • 71
  • 6
1
vote
1 answer

Delete Element and/or Element-Container Relationship in JXA (Javascript for Automation)

In Javascript for Automation, one can create an element object and then add it to a container. For instance: var cal = Application('Calendar') var newEvent = cal.Event( { summary: todoSummary, …
1
vote
3 answers

Get the string from selected text/ highlighted text using JXA

I'm supper new here, either Javascript and JXA, so pardon me if I make some stupid questions. But I'm trying to figure out a way to get the string from the highlighted text using JXA - JavaScript for Automation, for Javascript can be recognized in…
Le Hoa
  • 23
  • 4
1
vote
0 answers

Reordering smart playlist with JXA (AppleScript JS with iTunes)

I am trying to make an AppleScript (in JS) that will reorder a smart playlist. I can currently reorder a non-smart playlist with track.move({to: playlist}); (so I can move any track within the playlist to the bottom), but that doesn't seem to work…
Dylanthepiguy
  • 1,621
  • 18
  • 47
1
vote
1 answer

How to maximize Safari window with JavaScript for Automation (JXA)?

I'm looking for a way to maximize the Safari window using JavaScript for Automation (JXA). I'm able to open Safari and to bring the window to front, but I can't find a way to open it in fullscreen. var safari =…