Skip to content

Instantly share code, notes, and snippets.

@grahams
Created January 31, 2017 18:02
Show Gist options
  • Save grahams/9aa80b06db160bc027e2aee70a685974 to your computer and use it in GitHub Desktop.
Save grahams/9aa80b06db160bc027e2aee70a685974 to your computer and use it in GitHub Desktop.
@grahams
Copy link
Author

grahams commented Jan 31, 2017

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:

  1. Launch Automator -> New Workflow -> Service
  2. Set the service to receive "Files or Folders" in "Finder"
  3. add a "Run Javascript" action and paste in the above

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".

@grahams
Copy link
Author

grahams commented Jan 31, 2017

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

@grahams
Copy link
Author

grahams commented Mar 9, 2022

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