Skip to content

Instantly share code, notes, and snippets.

@scooby
Created April 30, 2020 05:13
Show Gist options
  • Save scooby/5727cffaca000b915dd6e96066541ec3 to your computer and use it in GitHub Desktop.
Save scooby/5727cffaca000b915dd6e96066541ec3 to your computer and use it in GitHub Desktop.
JXA is nuts
// Use this with https://onflapp.wordpress.com/lincastor/
// Lets you create double-clickable relative links in MacOS that sync over google drive and such.
// A "link" is just a text file with a relative path.
var app = Application.currentApplication();
app.includeStandardAdditions = true;
function readUrl(url) {
var urlObj = $.NSURL.alloc.initWithString(url);
return $.NSString.alloc.initWithContentsOfURL(urlObj).UTF8String.trim();
}
function relativeUrl(base, relative) {
var baseUrl = $.NSURL.alloc.initWithString(base);
return $.NSURL.alloc.initWithStringRelativeToURL(relative, baseUrl);
}
function handle_url (args) {
var linkContents = readUrl(args.URL);
var target = relativeUrl(args.URL, linkContents);
var url = target.absoluteString.UTF8String;
app.openLocation(url);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment