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
16
votes
2 answers

Can AppleScript now be replaced with JavaScript?

I have a book on AppleScript that I'm wondering whether I should keep. I already know JavaScript. I understand that Apple added JavaScript scripting support into OS X recently. Does this mean that I don't have to learn AppleScript anymore to do…
stackoverflowuser
  • 1,157
  • 9
  • 18
13
votes
2 answers

Using OS X JavaScript for Automation (JXA) to listen to "open location" Apple Event

I am using OS X JavaScript for Automation (JXA), and I want to be able to capture the "open location" Apple Event. Per http://www.macosxautomation.com/applescript/linktrigger/ , I have setup a customer URL handler. How do I do the equivalent of on…
big lep
  • 879
  • 6
  • 9
10
votes
2 answers

JXA: Set UTF-8 encoding when writing files

If I write a textfile using the standardadditions, I obviously can configure the encoding in a parameter bag. In AppleScript I would write «class utf8» but which value to use in JXA? I tried the Strings "UTF8", "utf8", "class utf8" without success.…
10
votes
3 answers

Listing all the files in a folder using JavaScript for Automation on Yosemite

I'm trying to port some old Applescript over to the new JavaScript syntax. Somethings seem to be pretty straight forward so : tell application "System Events" to keystroke "t" using command down becomes : System = Application('System…
9
votes
2 answers

How can I find out all the methods on a JXA object?

I'm trying to list all the methods of a JXA object. I've tried several methods that work with JavaScript in the browser, but none have worked: >> Object.getOwnPropertyNames(Application('Finder').selection()[0]); => ["__private__"] >> >>…
stiemannkj1
  • 4,418
  • 3
  • 25
  • 45
8
votes
1 answer

Javascript for Automation (OSA) Yosemite: privilege error for certain StandardAddition commands

In Yosemite it now is possible to use JavaScript for automation as well as Applescript. I am having trouble with certain StandardAdditions commands. E.g. from the Contacts application I can use displayAlert, but not displayNotification. Both are in…
wivku
  • 2,457
  • 2
  • 33
  • 42
7
votes
7 answers

How to get POSIX path of the current script's folder in JavaScript for Automation?

In AppleScript it’s possible to get the the POSIX path of the folder the current script is located in using this line: POSIX path of ((path to me as text) & "::") Example result: /Users/aaron/Git/test/ What’s the JavaScript equivalent?
aaronk6
  • 2,701
  • 1
  • 19
  • 28
6
votes
2 answers

Can't find JXA documentation

where can I find JXA documentation with all available classes, functions and parameters? After so far found just random code samples and short tutorials.
Jonas
  • 4,683
  • 4
  • 45
  • 81
6
votes
5 answers

Get POSIX path of active Finder window with JXA AppleScript

I would like the JXA equivalent of this AppleScript snippet: tell application "Finder" # Get path set currentTarget to target of window 1 set posixPath to (POSIX path of (currentTarget as alias)) # Show dialog display dialog…
Kymer
  • 1,184
  • 8
  • 20
6
votes
2 answers

How Can I Run JXA from Swift?

If I have a string variable with JXA source code, is there a way to run that from swift? It seems NSAppleScript only works with AppleScript source.
jl303
  • 1,461
  • 15
  • 27
6
votes
2 answers

Calling Shell Script with JavaScript for Automation

Using AppleScript I can call a shell script with: do shell script "echo 'Foo & Bar'" But I can't find a way to do this with JavaScript in the Yosemite Script Editor.
sverrejoh
  • 16,464
  • 13
  • 41
  • 29
6
votes
2 answers

Send email with attachment using Javascript for Automation

I would like use Javascript for Automation in OS X Yosemite to create a new email message in Mail.app and attach a file to the email. This is my code: Mail = Application('com.apple.Mail') message = Mail.OutgoingMessage().make() message.visible =…
Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
6
votes
2 answers

Attach event listeners in OS X JavaScript for Automation (JXA)

How is it possible to listen for events in OS X JavaScript for automation. In the scripting Library for the Messages application there is a list of event handlers, such as messageSent and messageReceived. However, I cannot figure out how to use…
5
votes
4 answers

How can I write UTF-8 files using JavaScript for Mac Automation?

In short - what is the JavaScript for Mac Automation equivalent of AppleScript's as «class utf8» ? I have a unicode string that I'm trying to write to a text file using JavaScript for Mac Automation. When writing the string to the file, any unicode…
Arieleo
  • 381
  • 3
  • 14
5
votes
4 answers

Using "whose" on arrays in Javascript for Automation

Playing with the new JS for automation using Script Editor. I'm getting an error on the final line of the following: var iTunes = Application("iTunes"); var sources = iTunes.sources(); var library = sources.whose({name : "Library"}); Confirmed that…
Ben Zotto
  • 70,108
  • 23
  • 141
  • 204
1
2 3
16 17