Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Set iChat/Adium status line to latest Twitter message Apps
Expand the reach of your Twitter status updates by making them propagate to your instant messaging accounts in iChat or Adium. Here's a Ruby script that grabs your latest Tweet and sets it as the status for iChat and Adium, if they're running. Add it to your crontab to run it regularly and keep in sync.

Instructions:
  1. Save the following code to ~/Library/Scripts, and name it sync-status-with-twitter.rb:
    #!/usr/bin/env ruby
    #
    # Update iChat/Adium status from Twitter
    #
    # Michael Tyson 
    # http://michael.tyson.id.au
    
    # Set Twitter username here
    Username = 'MyUserName'
    
    require 'net/http'
    require 'rexml/document'
    
    # Download timeline XML and extract latest entry
    url = "http://twitter.com/statuses/user_timeline/" + Username + ".atom"
    xml_data = Net::HTTP.get_response(URI.parse(url)).body
    doc    = REXML::Document.new(xml_data)
    latest = doc.root.elements['entry/content']
    message = latest.text.gsub(/^[^:]+:\s*/, '')
    
    exit if ! message
    
    # Apply to status
    script = 'set message to "' + message.gsub(/"/, '\\"') + "\"\n" +
             'tell application "System Events"' + "\n" +
             'if exists process "iChat" then tell application "iChat" to set the status message to message' + "\n" +
             'if exists process "Adium" then tell application "Adium" to set status message of every account to message' + "\n" +
             'end tell' + "\n"
    
    IO.popen("osascript", "w") { |f| f.puts(script) }
  2. Open it in, say, TextEdit and replace MyUserName at the top of the file to your actual Twitter username.
  3. Open Terminal (in Applications » Utilities), and make the script executable: chmod +x ~/Library/Scripts/sync-status-with-twitter.rb
  4. Open your crontab: crontab -e
  5. Add a line to crontab to run the script regularly:
    • Press o to insert a new line
    • Paste the following line:
      */30 * * * * ~/Library/Scripts/sync-status-with-twitter.rb
      The 30 here means run every 30 minutes. Change it if you want. Some alternatives for the first bit are:
      • */10 * * * * -- Every 10 minutes
      • 0 * * * * -- Hourly, on the hour
      • 0 */2 * * * -- Every second hour, on the hour.
  6. Press escape to stop editing
  7. Hold down shift and press ZZ (Z key twice) to save and quit
You're done. Wait a little bit and it'll update, or if you like, run it immediately from Terminal (~/Library/Scripts/sync-status-with-twitter.rb). If you want to update Facebook too, you'll have to add the Twitter application to Facebook itself. This script was inspired by a similar script by John Nunemaker over at RailsTips.org. Thanks, John.

For more help with this script, please see the original post on my blog.

[robg adds: I haven't tested this one.]
    •    
  • Currently 1.57 / 5
  You rated: 1 / 5 (7 votes cast)
 
[19,998 views]  

Set iChat/Adium status line to latest Twitter message | 7 comments | Create New Account
Click here to return to the 'Set iChat/Adium status line to latest Twitter message' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Great Script, But About the Hint...
Authored by: VxJasonxV on Oct 13, '08 08:50:00AM

The script itself is grand. I love seeing things like this, whether they're in ruby, applescript, or anything else.

For the rest of the hint, it'd probably be better to teach launchd interaction rather than cron interaction.

I love crontab, and have for all my life, but that is not a love shared by Apple. Cron systems are being phased out (at least as plans stand) in favor of launchd.

... I need to learn the stupid thing too >_<, Lingon is my best friend at the moment.



[ Reply to This | # ]
Set iChat/Adium status line to latest Twitter message
Authored by: bed42 on Oct 13, '08 02:40:16PM

Thanks! Works well (using Adium here). This interactivity between everything is the way of the future.

Oh, and I agree, launchd should be used fore future-proofing. :D



[ Reply to This | # ]
Set iChat/Adium status line to latest Twitter message
Authored by: mikedfunk on Oct 14, '08 06:08:34AM
what the heck? why bother? this can be done MUUUUCH more easily with the twitterAdium plugin. I'd call this reinventing the wheel with a bunch of switches and meters on it. It's easy as pie, just install and put %_Twitter in your status. I use this in combination with the xbox live status integration. That way I can put both statuses in my adium status automagically.

[ Reply to This | # ]
Set iChat/Adium status line to latest Twitter message
Authored by: dandiemer on Oct 20, '08 10:23:37AM

While what mikedfunk said about ease of use is true, the problem is that twitter limits API requests to 70 per hour. If you use the adiumtwitter script to access twitter in addition to using a desktop app to post tweets and a mobile app (like on the iPhone) you will quickly hit that limit. This script cannot be hit with a limit because it's working around the API and pulling it straight off the site. Props to whoever wrote this.



[ Reply to This | # ]
Revised to use plist, passwords, and update skype
Authored by: nlb666 on Oct 24, '08 03:43:06PM

Great hint! I played around with this a little as we're just getting our twittering rolling over at liketribe, and derived the following shell script that would update your Adium and Skype status from twitter even if your twitter updates are protected, plus a plist to go with it. The script could be a little more succinct, but at least its relatively easy to read and mod if desired.

  • Save the following in ~/Library/Scripts as "sync-status-with-twitter.sh"
    
    #/bin/sh
    userid=$1
    password=$2
    message=`curl -s -u $userid:$password "http://twitter.com/statuses/user_timeline/$userid.atom?count=1" | grep '<entry>' -A 5 | grep "<title>" | perl -pi -e "s/<title>|<\/title>|$userid:| //g" | perl -pi -e 's/"/\\"/g'`
    
    osascript -e "tell application \"System Events\"
    if exists process \"Adium\" then
       tell Application \"Adium\"
          set the status message of every account whose status type is available to \"$message\"
       end tell
    end if
    if exists process \"Skype\" then
       tell Application \"Skype\"
          send command \"SET PROFILE MOOD_TEXT\" & \"$message\" script name \"updater\" 
       end tell
    end if
    end tell"
    
  • Save the following as in ~/Library/LaunchAgents as com.liketribe.twitterstatus.plist. Replace YOUR TWITTER NAME, YOUR TWITTER PASSWORD, and YOUR HOME DIRECTORY with the appropriate values.
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>Label</key>
        <string>com.liketribe.twitterstatus.plist</string>
        <key>ProgramArguments</key>
        <array>
            <string>/bin/sh</string>
            <string>/Users/YOUR HOME DIRECTORY/Library/Scripts/sync-status-with-twitter.sh</string>
            <string>YOUR TWITTER USER ID</string>
            <string>YOUR TWITTER PASSWORD</string>
        </array>
        <key>RunAtLoad</key> <false/>
        <key>StartInterval</key> <integer>300</integer>
    </dict>
    </plist>
    
  • Execute "launchctl load ~/Library/LaunchAgents/com.liketribe.twitterstatus.plist" to get this running in the background updating every 300 seconds. You can test first by executing "sh ~/Library/Scripts/sync-status-with-twitter.sh YOUR-TWITTER-ID YOUR-TWITTER-PASSWORD" (substituting your twitter id and password of course) to make sure all is well. Skype for example might ask you to grant permissions to the script the first time you execute it.


  • [ Reply to This | # ]
    Updated sync script
    Authored by: nlb666 on Oct 25, '08 04:50:54AM
    Sorry all I just noticed my sync script appears to start Adium/Skype rather than simply check when they're running. This one, on Tiger at least, seems to avoid that side effect. Replace ~/Library/Scripts/sync-status-with-twitter.sh with the following:
    
    #/bin/sh
    userid=$1
    password=$2
    message=`curl -s -u $userid:$password "http://twitter.com/statuses/user_timeline/$userid.atom?count=1" | grep '<entry>' -A 5 | grep "<title>" | perl -pi -e "s/<title>|<\/title>|$userid:| //g" | perl -pi -e 's/"/\\"/g'`
    
    bool=`osascript -e "tell application \"System Events\" to set isRunning to count processes whose name is \"Adium\""`
    if [ "$bool" -gt 0 ]; then
    osascript -e "tell application \"Adium\" to set the status message of every account whose status type is available to \"$message\""
    fi
    
    bool=`osascript -e "tell application \"System Events\" to set isRunning to count processes whose name is \"Skype\""`
    if [ "$bool" -gt 0 ]; then
    osascript -e "tell application \"Skype\" to send command \"SET PROFILE MOOD_TEXT\" & \"$message\" script name \"updater\""
    fi
    
    Now you'll need to reload the plist file and all should be well
    
    launchctl unload ~/Library/LaunchAgents/com.liketribe.twitterstatus.plist
    launchctl load ~/Library/LaunchAgents/com.liketribe.twitterstatus.plist
    


    [ Reply to This | # ]
    Set iChat/Adium status line to latest Twitter message
    Authored by: bed42 on Feb 02, '09 04:46:06PM
    I've updated the original script so it will ignore @reply tweets. See http://abednarz.net/wp/twitter-adium-status-syncing-ignoring-replies/ for modified script.

    [ Reply to This | # ]