javascript-automation

Use Javascript for automation (JXA) to create a plist

天大地大妈咪最大 提交于 2019-12-08 14:43:46
问题 I'm looking into creating a JXA to build a plist. My starting point is an AppleScript that I found here. I came up with this snippet: var se = Application('System Events'); var item1 = se.PropertyListItem({kind: "string", name: "employee_name", value: employeeName}).make(); var plistFile = se.PropertyListFile({name: '/Users/armando/Desktop/x.plist', PropertyListItem: [item1]}).make(); ScriptEditor compiles without errors, the file got created but no entries are produced on the file. I guess I

Pipe to subprocess stdin for JXA

谁说我不能喝 提交于 2019-12-08 04:00:38
问题 I would like to start a subprocess in JavaScript for Automation (JXA) and send a string to that subprocess's stdin which might include newlines, shell metas, etc. Previous AppleScript approaches for this used bash's <<< operator, string concatenation, and quoted form of the string. If there was a JavaScript equivalent of quoted form of that I could trust to get all of the edge cases, I could use the same approach; I'm investigating regex methods toward that end. However, I thought since we

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

故事扮演 提交于 2019-12-08 03:58:00
问题 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 characters present become question marks in the file (ASCII char 3F ). If this was an AppleScript script instead of a JavaScript one, I could have solved this by adding the as «class utf8» raw statement as explained on Takashi Yoshida's Blog (https

How to click UI element using JXA

六眼飞鱼酱① 提交于 2019-12-08 03:35:02
问题 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 find how make a call. Code snippet which I tried in Script Editor: var app = Application('my_application_path') app.window.click.at('{100,100}') Thank you for help 回答1: You can interact with an application's user interface using the System Events

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

血红的双手。 提交于 2019-12-07 08:34:18
问题 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 them. Trying to pass a function yields an error, and trying to set these variables to new functions causes the REPL to hang. What is the proper way to set up these event handlers? 回答1: You would create a script that you then select from the

Pipe to subprocess stdin for JXA

南楼画角 提交于 2019-12-07 01:58:29
I would like to start a subprocess in JavaScript for Automation (JXA) and send a string to that subprocess's stdin which might include newlines, shell metas, etc. Previous AppleScript approaches for this used bash's <<< operator, string concatenation, and quoted form of the string. If there was a JavaScript equivalent of quoted form of that I could trust to get all of the edge cases, I could use the same approach; I'm investigating regex methods toward that end. However, I thought since we have access to unistd.h from JXA, why not try to just call $.pipe , $.fork , and $.execlp directly? $

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

不想你离开。 提交于 2019-12-05 18:43:54
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 them. Trying to pass a function yields an error, and trying to set these variables to new functions causes the REPL to hang. What is the proper way to set up these event handlers? You would create a script that you then select from the AppleScript handler menu in Preferences > General . Use the built-in Speak Events.applescript file as your guide and

JXA: Accessing CFString constants from CoreServices

流过昼夜 提交于 2019-12-04 13:05:37
JXA , with its built-in ObjC bridge, exposes enumeration and constants from the Foundation framework automatically via the $ object; e.g.: $.NSUTF8StringEncoding // -> 4 However, there are also useful CFString constants in lower-level APIs that aren't automatically imported, namely the kUTType* constants in CoreServices that define frequently-used UTI values, such as kUTTypeHTML for UTI "public.html" . While you can import them with ObjC.import('CoreServices') , their string value isn't (readily) accessible, presumably because its type is CFString[Ref] : ObjC.import('CoreServices') // import

Using “whose” on arrays in Javascript for Automation

我的梦境 提交于 2019-12-04 12:33:07
问题 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 the sources array is as expected (two elements, one with name "Library" and one "Internet Radio"). But that final line chokes with Error on line 3: TypeError: undefined is not a function (evaluating 'sources.whose({name : "Library"})') . As far as

Can you write folder actions with javascript (jxa)?

非 Y 不嫁゛ 提交于 2019-12-02 09:54:53
问题 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. 回答1: Using Automator I could build a Folder Action workflow to display the path of a file moved to a folder using only JavaScript: function run(input, parameters) { var app = Application.currentApplication(); app.includeStandardAdditions = true; var text = "FileName = " + input[0]; var options = { }