Last active
December 29, 2022 07:33
-
-
Save kenmickles/bf8ffbf7117f4b394ff01c8edac11ebd to your computer and use it in GitHub Desktop.
AppleScript to SCP a file to a server and copy the path. Useful for sharing screenshots, etc.
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
use framework "Foundation" | |
use scripting additions | |
property scpTarget : "[email protected]:~/public_html/uploads" | |
property publicPath : "https://example.com/uploads/" | |
on open fileList | |
repeat with thisFile in fileList | |
set itemPath to the quoted form of the POSIX path of thisFile | |
do shell script ("scp " & itemPath & " " & scpTarget) | |
tell application "Finder" to set fileName to name of thisFile | |
set publicURL to urlEncode(publicPath & fileName) | |
set the clipboard to {text:(publicURL), Unicode text:publicURL} | |
end repeat | |
end open | |
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