Automatically Send Toots To The Mastodon Social Network

I’m a user of the new Twitter-like social network Mastodon and the need to automatize sending content on a regular basis to Mastodon soon pushed me to develop my own tools like Feed2toot (RSS to Mastodon) and Boost (automatically boost messages).

But I also needed a command-line client for the Mastodon Network in order to automatically toot on a regular basis.

Le réseau social Mastodon

After some time to compare the different available CLI clients, I fell in love with Toot, a command-line client for the Mastodon Network by Ivan Habunek. In the next chapters, I’ll explain how to install Toot and use it for simple message or more complex ones with images.

Install the Toot client

Just use Pip to install toot with the following command:

# pip3 install toot

Now you need to log in the instance you will send messages to with the following command:

$ toot login

If the credentials you provided are correct, you are now ready to toot! Let’s try to add the most simple possible toot on my timeline:

$ toot post test
Toot posted:

Here is the result on my timeline:

Example of a toot sent from the command line

Adding line breaks in your toots

For a long time I could not use Toot for complex toots because I could not succeed adding line breaks in the message, which strongly restricts the possibilities.

Ivan Habunek, the creator of Toot, provided a solution replying to my bug report and I was soon using Toot like crazy! Here is how to add a line break in your toots:

$ toot post $'first line\n\nhow to escape a single quote \'\n\nlast line'

Here is the result:

How to use line breaks in your toots

Send toots with images

Ok, the last missing feature to send interesting toots for your followers is attaching images with your toots. With the Toot command line client, it’s quite easy. Just use the following command:

$ toot post -m /home/carlchenet/carlchenet-blog.png $'Read my blog for latest information about automatically sending content to #Mastodon\n\nMy Blog:'

The option -m allows to attach an image. Every word starting with a # will be a hashtag and all urls will be correctly displayed. If you need to notify someone from the current instance, use the name of this account starting with a @. If his account is not on the same instance, use the full name

Define when sending toots

Simple is beautiful, so I use my good old crontab. Considering my last example, I’ll create a simple script in /home/carlchenet/ sending my toot:

toot post -m /home/carlchenet/carlchenet-blog.png $'Read my blog for latest information about automatically sending content to #Mastodon\n\nMy Blog:'
exit 0

Just make this script executable:

chmod u+x /home/carlchenet/

Last step to send my toot each day at 10AM, add a line in your crontab:

00 10 * * * carlchenet /home/carlchenet/

Now we’re ready! My toot will be sent to Mastodon every day at 10AM.

My Other blog Posts About Automatically Sending Content To Mastodon

With great powers come great responsabilities

The Toot client allows sending automatically really cool stuff to Mastodon, but always think about the noise for your users it can generate if you use it too much.

As always while automatizing stuff, use it in a smart way and everybody will enjoy it.

… and finally

You can help me developing tools for Mastodon by donating anything through Liberaypay (also possible with cryptocurrencies). Any contribution will be appreciated. That’s a big factor motivation 😉

You also may follow my account @carlchenet on Mastodon 😉

Carl Chenet On Mastodon

5 thoughts on “Automatically Send Toots To The Mastodon Social Network

  1. Ça existe encore Mastodon ?

    Je crois que c’est le pire réseau social que j’ai pu tester…L’extrême gauche dans toute sa splendeur !

  2. Hi, in our Mastodon instance we would need a boot that BOOSTS all toots where the user is mentioned.
    User name = News
    When I toot: “@News There is free chocolate in the canteen”
    the BOOST2 boot boosts it and all follower of @News are notified.

    I think this is very similar to what you have done. Do you know if it exists? Could you give as a hand? We are trying to build a system to coordinate multiple grassroots democracy groups within an instance at DiEM25. Thanks

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *