Topic:   [Applescript] Posting a Tweet to Twitter   (Read 1637 times)


0 Members and 1 Guest are viewing this topic.

GMG Hendo


  • GMG-er

  • **


  • Posts: 155

  • [WITTY TEXT GOES HERE]
    • View Profile
[Applescript] Posting a Tweet to Twitter
« on: May 11, 2009, 06:50:24 AM »
This is how you post a tweet to Twitter using Applescript and a clever little cURL call.

Code: [Select]
property theUser : "usernamehere" -- your username
property thePassword : "passwordhere" -- your password
on postTweet(theUser, thePassword, theMessage)
set TwitterUpdate to "/usr/bin/curl" & ¬
" --user " & quoted form of (theUser & ":" & thePassword) & ¬
" --data status=" & quoted form of encodeURL(theMessage) & ¬
" http://twitter.com/statuses/update.xml"

-- Now try sending the Tweet to Twitter


set TwitterResponse to do shell script TwitterUpdate

if TwitterResponse contains "Could not authenticate" then
return "Tweet failed to post. Your username or password may be incorrect, or Twitter might be expieriencing difficulties."
else
return "Tweet successfully posted"
end if
end postTweet

on encodeURL(someURL)
return do shell script "/usr/bin/python -c '" & ¬
"from sys import argv; " & ¬
"from urllib import quote; " & ¬
"print quote(unicode(argv[1], \\"utf8\\"))' " & quoted form of someURL
end encodeURL


postTweet (theUser, thePassword, "I'm posting this tweet through Applescript! Awesome!")