Created
January 31, 2017 18:02
-
-
Save grahams/9aa80b06db160bc027e2aee70a685974 to your computer and use it in GitHub Desktop.
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
function run(input, parameters) { | |
var app = Application.currentApplication() | |
app.includeStandardAdditions = true; | |
for(var x = 0; x < input.length; x += 1) { | |
var filePath = input[x].toString() | |
if(filePath.length > 0) { | |
var escaped = escape(filePath); | |
if( (escaped.toLowerCase().indexOf("resilio") > -1) && | |
(escaped.toLowerCase().indexOf("public") > -1) ) { | |
var pubUrl = escaped.replace(/^.*Resilio%20Sync\/Public/, "http://grahams.wtf/public") | |
app.setTheClipboardTo(pubUrl) | |
delay(.25); | |
} | |
} | |
} | |
} |
If you'd prefer a more standard Javascript-for-Automation script (to run, say, from Alfred or Keyboard Maestro): https://gist.github.com/grahams/27288cdf5bd17aa59d570e69d6349fb8
This script more or less works for Shortcuts as well. You want receive files from Quick Actions -> Run JS for Automation with Shortcut Input -> Copy JavaScript Result to clipboard
function run(input, parameters) {
for(var x = 0; x < input.length; x += 1) {
var filePath = input[x].toString()
if(filePath.length > 0) {
var escaped = escape(filePath);
if( (escaped.toLowerCase().indexOf("resilio") > -1) &&
(escaped.toLowerCase().indexOf("public") > -1) ) {
var pubUrl = escaped.replace(/^.*Resilio%20Sync\/Public/, "http://grahams.wtf/public")
return(pubUrl);
}
}
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I created a Resilio Sync share that is on my desktop as well as a machine running a public web server. When I add files to the share from my local machine, it's mirrored into that public web space. I did this to replicate the Dropbox "Public" folder functionality.
I wanted a right-click menu for copying an http link to this file, so I created the above. You can use that JXA code in Automator:
You should be good to go.
If you select multiple files it tries to copy links to each of them to the clipboard (so if you are using a clipboard manager like Alfred you see multiple clipboard entries) but the delay is a little fiddly so you may have to tweak it for them to actually show up. If you don't want this multiple selection nonsense you can eliminate the for loop and the dependency on the app/app.setTheClipboardTo stuff and just return pubUrl. Then you could attach an "Copy to Clipboard" action to the output of "Run Javascript".