Skip to content

Instantly share code, notes, and snippets.

@ylorn
Created March 1, 2014 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ylorn/9284995 to your computer and use it in GitHub Desktop.
Save ylorn/9284995 to your computer and use it in GitHub Desktop.
set theExtensions to {"jpg", "png", "gif", "jpeg"}
set userAgent to "[Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.74.9 (KHTML, like Gecko) Version/7.0.2 Safari/537.74.9]"
set theUrl to "http://people.cs.clemson.edu/~zhaoyul/development/imageshack/tempIS.php"
set theResponses to {}
tell application "Finder"
set selectedFiles to selection
set fileNum to number of items in selectedFiles
set oldDelims to AppleScript's text item delimiters
if selectedFiles is not {} then
repeat with i from 1 to fileNum
set theFile to item i of selectedFiles
set thePath to POSIX path of (theFile as string)
set fileName to (name of theFile) as string
set AppleScript's text item delimiters to {"."}
set fileExtension to last text item of fileName
set the fileExtension to do shell script "echo " & quoted form of (fileExtension) & " | tr A-Z a-z"
if fileExtension is in theExtensions then
set theResponse to do shell script "curl -A " & quoted form of (userAgent) & " -X POST -F fileupload=@" & quoted form of thePath & " -F upload=Go -F title=" & quoted form of fileName & " " & quoted form of theUrl
set theResponse to "http://" & theResponse
set the end of theResponses to theResponse
end if
end repeat
end if
end tell
set theResult to joinList(theResponses, {"
"})
if theResult is not "" then
set the clipboard to theResult as text
end if
set AppleScript's text item delimiters to oldDelims
to joinList(aList, delimiter)
set retVal to ""
set AppleScript's text item delimiters to delimiter
set retVal to aList as string
return retVal
end joinList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment