Created
January 5, 2009 05:07
-
-
Save youpy/43270 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
tell application "iTunes" | |
set iname to name of current track | |
set iartist to artist of current track | |
if iartist is not equal to "" then | |
set iartist to iartist & " - " | |
end if | |
tell application "Keychain Scripting" | |
set twitter_key to first Internet key of current keychain whose server is "twitter.com" | |
set twitter_login to quoted form of (account of twitter_key & ":" & password of twitter_key) | |
end tell | |
set twitter_status to quoted form of ("status=" & urlencode("listening " & text returned of (display dialog "now playing:" default answer (iartist & iname))) of me) | |
set results to do shell script "curl --user " & twitter_login & " --data-binary " & twitter_status & " http://twitter.com/statuses/update.json" | |
end tell | |
# http://harvey.nu/applescript_url_encode_routine.html | |
on urlencode(theText) | |
set theTextEnc to "" | |
repeat with eachChar in characters of theText | |
set useChar to eachChar | |
set eachCharNum to ASCII number of eachChar | |
if eachCharNum = 32 then | |
set useChar to "+" | |
else if (eachCharNum ≠ 42) and (eachCharNum ≠ 95) and (eachCharNum < 45 or eachCharNum > 46) and (eachCharNum < 48 or eachCharNum > 57) and (eachCharNum < 65 or eachCharNum > 90) and (eachCharNum < 97 or eachCharNum > 122) then | |
set firstDig to round (eachCharNum / 16) rounding down | |
set secondDig to eachCharNum mod 16 | |
if firstDig > 9 then | |
set aNum to firstDig + 55 | |
set firstDig to ASCII character aNum | |
end if | |
if secondDig > 9 then | |
set aNum to secondDig + 55 | |
set secondDig to ASCII character aNum | |
end if | |
set numHex to ("%" & (firstDig as string) & (secondDig as string)) as string | |
set useChar to numHex | |
end if | |
set theTextEnc to theTextEnc & useChar as string | |
end repeat | |
return theTextEnc | |
end urlencode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment