Created
March 6, 2021 18:05
-
-
Save jhenry/325631e73870c82ce236ad3feb8272e3 to your computer and use it in GitHub Desktop.
Folder Action Handler to upload an added file and copy URL
This file contains 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
(* | |
droplet - upload and copy url | |
This Folder Action handler is triggered whenever items are added to the attached folder. | |
The script uploads the file to the specified destination, and puts the URL in the clipboard. | |
Adapted from Ken Mickels' gist: | |
https://gist.github.com/kenmickles/bf8ffbf7117f4b394ff01c8edac11ebd | |
*) | |
use framework "Foundation" | |
use scripting additions | |
property scpTarget : "you@example.com:~/public_html/s" | |
property publicPath : "https://example.com/s/" | |
on adding folder items to this_folder after receiving theFiles | |
try | |
repeat with thisFile in theFiles | |
tell application "Finder" to set fileName to name of thisFile | |
display notification fileName with title "Syncing File..." | |
set itemPath to the quoted form of the POSIX path of thisFile | |
do shell script ("scp " & itemPath & " " & scpTarget) | |
set publicURL to urlEncode(publicPath & fileName) | |
set the clipboard to {text:(publicURL), Unicode text:publicURL} | |
display notification fileName with title "Uploaded and copied URL" | |
end repeat | |
end try | |
end adding folder items to | |
on urlEncode(input) | |
tell current application's NSString to set rawUrl to stringWithString_(input) | |
set theEncodedURL to rawUrl's stringByAddingPercentEscapesUsingEncoding:4 -- 4 is NSUTF8StringEncoding | |
return theEncodedURL as Unicode text | |
end urlEncode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment