Murphy Mac - Screencasts and Tutorials » Page 'Twitter While You Sleep'

Twitter While You Sleep


TwitterWait until you see what a clever pun this title is. Using the sleep command in Terminal you can update your Twitter status while you’re away. Or sleeping.

Apple has jumped around a little with regards to command line scheduling tools, but the sleep command is still dead-simple to use. (Read more about scheduling with lingon and launchd here)

Suppose you have a command you want to run once, at a future time. Use sleep followed by the number of seconds to wait. Then use a semi-colon to separate the command to run at the appointed time.

sleep 30 ; command

The above example will execute command 30 seconds after you hit the return key. 3600 seconds is an hour. 86,400 seconds in each and every day.

So now you just need a command to update Twitter. The curl command comes with your Mac. Twitter Development Talk boasts the easiest way to update Twitter from the command line. Scroll down to The Easiest Way to Play Around with the Twitter API. Christopher Penn has a post on it too, but the command is cut-off on his blog.

The command should look like this:

curl -u username:password -d status=”your message here”

Enter that all on one line. It would be better to make it into a shell script. Just copy that line into a text file, maybe name it, and replace the your message here part with $1. Then use chmod to make it executable.

Note: Don’t know how to make it executable? Read more about making a shell script. Learn even more about shell scripts: make an interactive shell script.

From there you can enter the following in the Terminal:

./ “Looking into starting my own airline…”

And you’ve updated your Twitter status.  You can make that cleaner by setting an alias for your shell script.

Finally, to have your tweet post onto Twitter hours later you could enter something like this in the Terminal:

sleep 7200; ./ “I’m sleeping” (you’ll need to leave your Mac on)

If you’re a stickler about your Twittering and want to be accurate, this is the way to go. Schedule that I’m in the shower tweet in advance. People need to know.

| Permalink

5 comments to “Twitter While You Sleep”

  1. You may as well use at(1) for this as this doesn’t block a terminal session with a long sleep and allows even more sillyness like
    $ echo “/path/to/ ‘I am still sleeping'” | at 0559
    $ echo “/path/to/ ‘Wakening up from alarm'” | at 0600
    $ echo “/path/to/ ‘Too late already'” | at 0700

  2. There’s a problem with doing : sleep 10; echo test
    If you run it, then 2 seconds later hit ctrl+c to abort it, the echo command still gets run.. but, if you run:
    sleep 10 && echo test
    and hit ctrl+c, it will not get echo’d (but if you wait, it will)

    The && checks the last command exited correctly before running, as opposed to just going though the list of commands regardless of errors..
    If the next command depends on the previous one completing (like mkdir blah, then cd blah – no point cd’ing if you can’t make the directory) you should really use &&..

  3. I’d prefer to use AT but it seems I remember there are some hoops to jump through to get AT working under Leopard? I didn’t look while writing this post but I have a vague recollection that AT is a hassle now.

    Note to self: Don’t follow Patrix on Twitter.

    Thanks dbr.

  4. I’ve researched quite a few spectacular details at Worth social bookmark for the purpose of returning to. I wonder the level of energy you put to create this type of good instructive webpage. Carry on the nice work!

  5. You can include the “priority” and “change frequency” tags in your sitemap.

    Concept designs are a fantastic means to arrange and prepare a site during
    the earliest, most pliable phases of the internet design procedure.
    Obviously, you will need your business name in the title of your home page but unless that name is also your keywords, add your keywords as well
    and you will rank much higher in the search engines.

Leave a comment