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 open location this_URL
...
end open location
with JXA? I tried all of the following, but could not get any of them to execute:
app = Application.currentApplication();
app.includeStandardAdditions = true;
function run() {
app.displayDialog(JSON.stringify(arguments));
}
function openLocation() {
app.displayDialog(JSON.stringify(arguments));
}
function openDocuments() {
app.displayDialog(JSON.stringify(arguments));
}
function onOpenLocation() {
app.displayDialog(JSON.stringify(arguments));
}
Apple's JXA docs (https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-10.html#//apple_ref/doc/uid/TP40014508-CH109-SW15 ) don't discuss how to handle the open location event. My script would get opened because I could get an alert to display if I added it outside the functions. I just couldn't get a function to execute and be passed in the URL.
I am working around this by having a AppleScript handler that that then invokes my JXA code, but this is certainly less than ideal.
I also didn't see anything in the JXA Cookbook (https://github.com/dtinth/JXA-Cookbook ) about this.
function openLocation(thisURL) { // process thisURL }
if it is meant to work… – Krasnoyarsk