Created
April 30, 2020 05:13
-
-
Save scooby/5727cffaca000b915dd6e96066541ec3 to your computer and use it in GitHub Desktop.
JXA is nuts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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