Skip to content

Instantly share code, notes, and snippets.

@kenmickles
Last active December 29, 2022 07:33
Show Gist options
  • Save kenmickles/bf8ffbf7117f4b394ff01c8edac11ebd to your computer and use it in GitHub Desktop.
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.
use framework "Foundation"
use scripting additions
property scpTarget : "user@example.com:~/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