JXA | JavaScript Automation packages | Runtime Evironment library
kandi X-RAY | JXA Summary
kandi X-RAY | JXA Summary
JavaScript for Automation(JXA) packages.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of JXA
JXA Key Features
JXA Examples and Code Snippets
Community Discussions
Trending Discussions on JXA
QUESTION
I have written a JXA script for Numbers that coverts a standard eCommerce order spreadsheet to the Stamps.com format for uploading the order, to print shipping labels. After 2 weeks of digging for info on JXA for Numbers, I have the conversion at 90%. But, I need to delete some non-relevant rows and can't get that function to work. I am also confused between .deleteRow() and .remove(). The commented-out code was a different attempt which also did not work. However, using the table.ranges["6:6"] I did manage to select (highlight) the entire row 6, but then no delete. Here is my current code (fragment).
...ANSWER
Answered 2022-Mar-20 at 11:28table.rows[marciRow-1].delete(); //the index is zero based
QUESTION
In an osascript/JXA context, I need to map macOS keyCodes and modifiers to Unicode strings (for any keyboard layout, specified at run-time)
The obvious candidate appears to be UCKeyTranslate
, but my attempts to get a reference to it from a JavaScript for Automation context have not been successful so far.
Does anybody know how to do this, perhaps in terms of ObjC.bindFunction
?
When ObjC libraries are imported into the 'JavaScript for Automation' (or 'JXA') JSContext, a global $
symbol is decorated with their methods.
So, for example, evaluating $.NSPasteboard
in a vanilla JXA context evaluates to undefined, but after ObjC.import('Appkit')
, we can write, and successfully evaluate, expressions like:
ANSWER
Answered 2021-Dec-29 at 14:33One way to go would be to make a Swift or ObjC helper library (or a command line tool), and then use that from JXA. Check some example code to start.
If you wrap this call in an ObjC object method inside a framework, it's possible to ObjC.import()
it and use in your scripts. If you choose to do a command line app, then call it as a shell command.
Using ObjC.bindFunction seems a bit too complicated, because you'd have to bind a few other functions that would get you a UCKeyboardLayout instance, and define a bunch of magic constants, plus do some necessary mapping of strings and pointers.
QUESTION
Back again with a JavaScipt / JXA question. I'm trying to register a response from a application that I'm calling with JXA. I am trying to register the value app.toDos.byId("HQebK1em72yZqc3WqTmyzx")
. When I kick of the following script:
ANSWER
Answered 2021-Sep-19 at 18:56That is expected: push
is a JavaScript standard library method that always returns the array length. Just do this instead:
QUESTION
I'm trying to implement automation for the task manager Things 3 on macOS using JXA (Javascript for macOS automation) and I'm running it to a strange error. I have spent countless hours trying to fix this myself and with the help of others. I am trying to use the following method described in the documentation:
As following:
...ANSWER
Answered 2021-Sep-12 at 13:33The Things documentation is wrong: schedule
is a method of Application
, not of ToDo
, which is why it asks for a todo specifier (it wouldn’t need that one if it was a property of a ToDo object already). The working code hence is:
QUESTION
I would like to get the id (or name) of the Apple Note (using the "notes" app on mac) that is currently in view (not a floated not, just the "selected" note), using either Applescript or JXA. Is that possible?
I know how to get the id of the most recently saved note with Applescript:
...ANSWER
Answered 2021-Jul-13 at 19:31I've also found the following to work on macOS 11+. I got the answer based on this macscripter.net discussion, which suggests it works starting with macOS 10.15, but I am not able to verify at the moment earlier than macOS 11:
QUESTION
Using Javascript for Automation (JXA) I want to identify the window the user has just clicked on. In other words, I want to identify the window that has just come to the front. How can I do that?
So far, I identify the front application, and try to get the window of that application which is in focus, like so:
...ANSWER
Answered 2021-Jun-02 at 12:24It is known bug of JXA. You can solve issue using abilities of AppleScript execution from JXA code. Following script will return front window of frontmost application:
QUESTION
I am running a JXA script as an agent using launchctl
. The main logic of the script is supposed to be run at intervals of 2 seconds, which I have achieved using an infinite loop and delay
. However, whenever my macbook goes to sleep the script stops execution and I have to unload and load the agent manually again.
My script:
...ANSWER
Answered 2020-Dec-02 at 04:21Based on the suggestion by CJK, I am now executing my JXA script, every 5 seconds, using launchctl
and the following plist
:
QUESTION
Given a dataset as follows:
...ANSWER
Answered 2020-Nov-22 at 13:00IIUC you can sort on axis=1
first before creating a line:
QUESTION
I have a script which assembles an xml document via string manipulation (which I wrote before I discovered the XML Suite).
When certain characters are included such as £, –(en-dash) and —(em dash) (I suspect all non-ascii characters), they're replaced with the unicode replacement character �
(U+FFFD)
.
This only happens when there is an xml header at the start of the document: i.e. . Making any change at all to this fixes the problem and writes what I would expect to the file. My assumption is that applescript is trying to parse the string as xml, but I want it to pass as a string.
I'm writing in JXA, but have included the Applescript equivalent as I think the issue is with OSA and there are likely more applescript users!
edit: ok, this is more an encoding issue I guess—reading as UTF-8 (which the xml I'm generating should be) results in the replacement character, but Western or Mac Roman display the characters correctly. UTF-8 definitely supports these characters though, so I'm not sure the best way to move forward?
edit 2: Just to be clear: I think what's happening is that the non-ascii characters are being encoded in something other than UTF-8, which is causing my XML output to be invalid. How can I get applescript or JXA to encode non-ascii characters as UTF-8?
Applescript
...
ANSWER
Answered 2020-May-19 at 16:37In AppleScript, you’d use write theText to theFile as «class utf8»
to write UTF8-encoded text. You can’t do that in JXA as there’s no way to write raw AE codes.
I generally recommend against JXA as it’s 1. buggy and crippled, and 2. abandoned. If you like JavaScript in general you’re far better off with Node. For application automation you’re best sticking to AppleScript: while it’s a crappy language and also moribund, at least it speaks Apple events right and has half-decent documentation and community support.
If you must use JXA, the only workaround is to write your UTF8 file via the Cocoa APIs instead. Though generating XML via string-mashing is evil and bug-prone anyway, so you’d probably be as well taking the opportunity to rewrite your code to use a proper XML API. (Again, with Node you’re spoiled for choice and the hardest part will be figuring which NPM libraries are robust and easy to use and which are junk. With AS/JXA, it’s either System Events’ XML Suite, which is slow, or Cocoa’s XML APIs, which are complex.)
QUESTION
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 array, but that can't be the best way to do count the number of objects.
The code runs in ScriptEditor on Mac OS 10.15
...ANSWER
Answered 2020-Mar-17 at 08:21To get the number of events in a single calendar:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install JXA
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page