<h2>Posting From the Command Line on Open Social Networks</h2>

<p>You can post to your open social media timelines from the command line using <a href="https://en.wikipedia.org/wiki/Application_programming_interface">API</a> access. Why would you want to do this?</p>

<ul>
	<li>Script automated postings.</li>
	<li>Bots</li>
	<li>Post from terminal environments.</li>
	<li>Post from wherever else you are without having to go to the social media site or to the client that you use to access it.</li>
	<li>Trigger postings via voice command (what I do).</li>
</ul>

<h2>On GNU Social</h2>

<p>Here is the basic format for the command to post a message to a Statusnet / GNU Social timeline:</p>

<p><code>curl -s --basic --user &lt;username:password&gt; --data status="Hello World" --output /dev/null https://instance.domain.com/api/statuses/update.xml</code></p>

<p>And here is the script I use to post a message to my timeline, launched by a blather voice command:</p>

<pre>
#!/bin/bash

# SN account info
user=johndoe
pass='password123'

# a place to store the text message 
text=/tmp/message.txt

# Virtual keystrokes to copy selected text to the clipboard
xdotool key Control+c

# pipe text out of clipboard into the text file
xclip -o > $text

# rest for half a sec
sleep .5

curl -s --basic \
--user $user:$pass \
--data status="$(cat "$text")" \
--output /dev/null \
https://instance.domain.com/api/statuses/update.xml 

rm $text

exit 0
</pre>

<h2>On Pump.io</h2>

<p>On <strong>pump.io</strong> you have to install the <code>pump.io</code> software on your computer. You don't have to be running a server, you just have to have the binaries so that you can run the commands. I will not go into how this is done on this podcast, but there's a link to the pump.io website below and there should be installation instructions available there. Once you have the software installed, you also have to allow command-line access to your account and get the token for authentication, maybe authorize the user too:</p>

<pre>
pump-register-app -s instance.domain.com -P 443 -t CLI
</pre>

<pre>
pump-authorize -s instance.domain.com -P 443 -u username
</pre>

<p>Finally you can post to your timeline from the command line:</p>

<p><code>pump-post-note -s instance.domain.com -P 443 -p -u username -n "Hello World."</code></p>

<p>My script to post a message to the <code>pump.io</code> timeline, launched by a blather voice command:</p>

<pre>
#!/bin/bash

# a place to put the text. 
text=/tmp/message.txt

# --------------------------------
# Since markdown is possible, I run 
# the text through markdown to get
# a bit of formatting and save it
# as a separate file 
# --------------------------------
pump=/tmp/pump.txt

# Virtual keystrokes to copy selected text to the clipboard
xdotool key Control+c

# pipe text out of clipboard into the text file
xclip -o > $text

# run Markdown
markdown $text > $pump

# Post message
pump-post-note -s instance.domain.com -P 443 -p -u username -n "$(cat $pump)"

sleep 1

rm $text
rm $pump

exit 0
</pre>
<h2>Links</h2>

<ul>
<li>GNU social: <a href="https://gnu.io/">https://gnu.io/</a></li>
<li><a href="https://identi.ca/">https://identi.ca/</a> (a <a href="https://pump.io/">pump.io</a> network)</li>
<li>pump.io Clients: <a href="https://github.com/e14n/pump.io/wiki/Clients">https://github.com/e14n/pump.io/wiki/Clients</a></li>
<li>My Screencast demonstrating the use of blather voice command to post to a timeline <a href="https://youtu.be/IJyzF_-6S2o">https://youtu.be/IJyzF_-6S2o</a></li>
</ul>
