Change your Skype availability status on Ubuntu via cron

I used Skype when it first came out and then stopped because there were only a few other people I knew who used it regularly. Since they were all in my local calling area, if I wanted to talk to any of them for free I could just use a phone.

I just started using it again — for work — to talk with customers and consultants who do not live in the Bay Area. However, I found that my Thursday telecommute days were causing problems: Skype would be running on my work computer and people trying to call me would get ring-no-answer because I was actually at home.

Turns out you can start and stop Skype via cron the same way you can start and stop Pidgin Instant Messenger via cron, you just need to set a few environment variables and it works great.

First create the script ~/bin/export_x_info which looks like this:

#!/bin/bash
# Export the dbus session address on startup so it can be used by cron
touch $HOME/.Xdbus
chmod 600 $HOME/.Xdbus
env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.Xdbus
echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.Xdbus
# Export XAUTHORITY value on startup so it can be used by cron
env | grep XAUTHORITY >> $HOME/.Xdbus
echo 'export XAUTHORITY' >> $HOME/.Xdbus

Create this script, type chmod 700 ~/bin/export_x_info so you can execute it, then execute it, then add it to System > Preferences > Sessions > Startup Programs so it will execute every time you start your computer and record the latest session address and XAUTHORITY value.

This script creates a 4-line file ~/.Xdbus with the current session address and XAUTHORITY value. By sourcing this file in the crontab file your scripts can now use dbus to send messages to X-Windows applications. To start and stop Skype at work I added these lines to my work computer’s crontab file:

# Skype on/off
00 09 * * Mon,Tue,Wed,Fri source ~/.Xdbus; /usr/bin/skype &
30 17 * * Mon,Tue,Wed,Fri killall skype

On my home computer I have:

# Skype on/off
00 09 * * Thu source ~/.Xdbus; /usr/bin/skype &
30 17 * * Thu killall skype

So on Thursdays when I telecommute Skype is running at home, the rest of the week it’s running at my office, and at night it’s turned off so customers aren’t calling me in the middle of the night.

When Skype isn’t running other users see your status as “Offline”. When cron restarts Skype it starts up with the same status it had when the process was killed. I just leave my status set to “Online,” so when cron starts Skype it shows everyone that I’m online. When cron kills the Skype process at the end of the day my status changes to “Offline” and people can’t call me.

Hope you find this useful.

One thought on “Change your Skype availability status on Ubuntu via cron

  1. Great! Thanks so much. I managed to migrate some of my notifiers to KDE4 (dbus…), but cron wouldn’t show them. Now it works fine!

    Cheers,
    Sven

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.