Uploading images to Imgur.com

There is this great script that used to work here with LaunchBar to upload images to imgur.com

https://forums.obdev.at/viewtopic.php?f=24&t=8284&p=31814#p31814

Based upon this — http://scriptlife.tumblr.com/post/19005232591/imgur

It has stopped working entirely. Does anyone here see a fix for this? Not sure if it’s because imgur changed something or if Apple changed something or a combination of the two.

on open input
   set thelist to {}
   tell application "Finder"
      -- convert file paths to posix
      set imageList to {}
      repeat with i from 1 to (count input)
         set end of imageList to POSIX path of (item i of input as alias)
      end repeat
      -- no images selected
      if (count imageList) is 0 then
         display dialog "No image files selected" with title "Imgur uploader" buttons {"Quit"} default button "Quit"
         return
         --upload
      else
         --set dialogResponse to display dialog "You are uploading " & (count imageList) & " image(s)." & return & return & "The images will show up in separate tabs in your default browser once they are uploaded." with title "Imgur uploader" buttons {"Upload", "Cancel"} default button "Cancel"
         --if button returned of dialogResponse is "Upload" then
         repeat with i from 1 to (count imageList)
            set apiKey to "26ff5c40cbedf50e7f81124ab473c1cc"
            set curlCommand to "curl -F \"key=" & apiKey & "\" -F \"image=@" & item i of imageList & "\" [url=http://api.imgur.com/2/upload]http://api.imgur.com/2/upload"[/url]
            set answer to do shell script curlCommand
            set atid to AppleScript's text item delimiters
            set AppleScript's text item delimiters to "<imgur_page>"
            set link to text item 2 of answer
            set AppleScript's text item delimiters to "<"
            set link to text item 1 of link
            set AppleScript's text item delimiters to atid
            set browser to my default_Browser()
            tell application browser to open location link
            set end of thelist to (link & "
") as text
            
         end repeat
         set the clipboard to thelist as text
         --   end if
      end if
   end tell
end open

on default_Browser()
   tell (system attribute "sysv") to set MacOS_version to it mod 4096 div 16
   if MacOS_version is 5 then
      set {a1, a2} to {1, 2}
   else
      set {a1, a2} to {2, 1}
   end if
   set pListpath to (path to preferences as Unicode text) & "com.apple.LaunchServices.plist"
   tell application "System Events"
      repeat with i in property list items of property list item 1 of contents of property list file pListpath
         if value of property list item a2 of i is "http" then
            set longName to value of property list item a1 of i
            set AppleScript's text item delimiters to "."
            set shortName to last text item of longName
            set AppleScript's text item delimiters to ""
            return shortName
         end if
      end repeat
      return "Safari"
   end tell
end default_Browser

Model: Sierra 10.12.2
Browser: Safari 10.0.2
Operating System: Other

My understanding is that your handler default_Browser rely upon a structure of the plist “com.apple.LaunchServices.plist” which is no longer the real one.
When I run this subset on the file available in Sierra, I see no object containing the string “http”

set {a1, a2} to {2, 1}

set pListpath to (path to preferences as Unicode text) & "com.apple.LaunchServices.plist"
tell application "System Events"
	repeat with i in property list items of property list item 1 of contents of property list file pListpath
		log (get value of property list item a2 of i)
		log (get value of property list item a1 of i)
		if value of property list item a2 of i is "http" then
			set longName to value of property list item a1 of i
			set AppleScript's text item delimiters to "."
			set shortName to last text item of longName
			set AppleScript's text item delimiters to ""
			--return shortName
		end if
	end repeat
end tell

I wish to add that for every system since 10.10, the code used to get the main version return a wrong value.
As you will have to edit your code for 10.12, I give below an enhanced one.

tell (system attribute "sysv") to set MacOS_version to it mod 4096 div 16
log MacOS_version --> 9
if MacOS_version ≥ 9 then
	set MacOS_version to (system attribute "sys2")
end if
--> 12

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) jeudi 5 janvier 2017 11:57:28