Blogging from the Command-Line

I'm a command-line person. If you can show me a command-line version of something I already do in a windowed environment, I'll get stuff done faster. I often look for command-line solutions to tasks that become repetitive and feel as though time could be saved by doing them on the console.

A recent example of this is the posting of asides on my blog. Asides are often very short (one or two sentences at most -- they appear on my blog without a title) and navigating the WordPress Administration interface in a web browser simply to post one or two sentences became very time consuming and distracting. Since I'm constantly editing files and code on the console using my favorite editor (vi), being able to quickly create and post an aside from the same environment would be awesome.

Before writing a tool that allowed me to post to my WordPress blog, I searched Google to see if someone else had already written something. Sure enough, I found blogpost, a script written in Python by Stuart Rackham:

blogpost is a WordPress command-line weblog client. It creates and updates weblog entries directly from AsciiDoc (or HTML) source documents. You can also delete and list weblog entries from the command-line.

It uses XML-RPC to post to WordPress blogs and also supports automatically uploading media files (images, videos, audio, documents) that are referenced within the AsciiDoc (or HTML) post file. Check the blogpost man page for full details.

Remember, my main goal here is to make posting short asides easier. I'm perfectly happy using the WordPress web interface to write longer posts. In fact, I prefer the web interface for longer posts because I get things like automatic spell checking (through OS X) and automatic draft saving (through WordPress).

After installing blogpost and modifying the configuration file to include my WordPress login details, I created a file called post.txt using the vi editor and, after saving the file and closing vi, I published the aside using blogpost:

$ --title="My Test Aside Post" -U --doctype='html' create post.txt
creating published post 'My Test Aside Post'...
id: 2758

$ cat --categories="Asides, Blog Entries, General" post.txt
assigning categories: Asides,Blog Entries,General

Note that I only need really basic formatting (i.e., HTML for links), so I use the --doctype='html' option. This allows me to type raw HTML in vi when I'm editing the post file, just as I do now in WordPress (I don't use the Visual Editor).

While the options and flexibility provided by blogpost are great, the process of publishing an aside needed to be more automated to solve my problem. Creating a new file in vi, typing all those options, running two separate commands, and then deleting the file every time I wanted to post a few sentences on my blog didn't make a whole lot of sense. So I whipped together this little shell script to help automate the steps above:

## - automates publishing asides using

# Open a temporary file in the vi editor
vi aside.$$

# Display new aside before publishing
echo "New Aside:"
cat aside.$$

# Prompt for an aside title
echo "Enter a title for this Aside:"
read TITLE
echo "OK!"

# Using the temp file saved above, post the Aside --title="$TITLE" -U --doctype='html' create aside.$$ cat --categories="Blog Entries, Asides" aside.$$

# Remove the temporary file
rm aside.$$

Now posting an aside to my blog is as simple as running ./, typing the aside in vi, saving and quitting (:wq), and then typing a title. The rest of the work, including cleanup, is taken care of by the script!

Stuart did an excellent job with blogpost and if you have a blog and use the console (and why shouldn't you?!) I recommend you check it out. The blogpost README is a great place to start, as it includes prerequisites and installation information.

Write a Comment


  1. You’re using HTML to write, does it support Markdown as well? If so, I can consider writing blog post on Ulysses III in Markdown and then copy + paste it on terminal. That way, posting blog posts will be very fast.

    In the article, you have mentioned you use it for Aside post format only. But I think it’s good for posting blog posts as well. Why did you consider using it only for Aside post and not the long blog post?

    And also, how do we upload image through the command line and use it in the blog post? Have you tried it?

    The only thing I’ll need to post a blog post are: Ability to add categories, tags, images, custom permalink, hyperlink, and location.

    Now just as I’m writing this I think it’s better to use WordPress instead of command line to post a large blog post. I’ll need to add Location which I can’t add on terminal, because I’ve used your Indie Pub Current Location plugin. Also, I’ll need to add SEO to the post (I use SEO Yoast).

    What do you think?

    • This post is 5 years old and I haven’t used this script in almost as much time. šŸ™‚

      I was originally using it for Asides because they were short, one-sentence posts. If I’m going to spend 3 to 48 hours working on a longer post, why would I want to post from the command line? I’m more likely to want to preview the post on WordPress and then review it once again (in Preview mode) for any last-minute changes.

      Posting from the command-line was for the convenience.

      That said, I do really love the idea of being able to post everything from the command line, to write everything in Markdown and also have a system for including categories, tags, permalink, location, etc. Also, image upload is another thing I’d love to see. I have a project on the backburner for this, a command line tool that allows you to upload files from the command line and returns a public URL that you can then use.

      Also, the jrnl program you linked me to looks really nice, far more polished than the script I mentioned here in this post! I’ll have to take that for a spin sometime.

      • I also think it’s better to post blog post through WordPress instead of command line.

        The only time I would use command line is to post something quickly, just like you did with Aside post format, but with ability to add categories, tags, location, etc.

        Also, image upload is another thing Iā€™d love to see. I have a project on the backburner for this, a command line tool that allows you to upload files from the command line and returns a public URL that you can then use.

        I’d love it! We can use that for almost anything, not only while posting blog post. For example, we can use terminal to post image in the web and link it through Markdown in any of our writings. While writing through Markdown I always have difficulty uploading picture in the Internet. With the command line tool, it’ll be fast and easy.

        jrnl is amazing. However, I am confused as what to do with it.

        I have more than 370 journal (more than 2 years) notes in Evernote with a picture of my face (I take photo of my face everyday while I write personal journal to see my face change overtime).
        I’m finding it pretty difficult to leave Evernote now.

        With Evernote, I have everything organized. I can search any journal entries I want quickly in my laptop, web, and my mobile phone. I can also write journals from my mobile phone and website when I’m not near to my laptop.

        Whereas, I can’t do that with jrnl. As a result, I’m having hard time trying to switch. I don’t know how I can make a switch, but I want to.

        Switching is probably one of the hardest thing to do in life.

        • I also use Evernote, but not as my primary journal. My primary journal is a collection of text files, one text file for each day with filename the same as the date of the journal (e.g., 2014-07-12.txt). I write in Markdown, in Ulysses.

          However, sometimes I’m not at my laptop and I can’t use my text editor (Ulysses) to add my journal. But I don’t want that physical limitation to prevent me from journaling. So sometimes I’ll journal from my iPad, or my iPhone, using Evernote, in an Evernote notebook called “Journal”. Sometimes I’ll be walking or driving and unable to type, so I’ll record an audio note using Evernote to be transcribed later and added to my actual journal.

          Then, once a month or so, I go through Evernote and move any text notes tagged move to journal over to my real journal (using Ulysses), creating a new file for each day and making sure the format in Ulysses is consistent. Also once a month or so, I’ll go through all my audio notes that have been tagged to transcribe and transcribe those (playing them and typing out what I’m saying in the audio note). Then I’ll transfer those to the journal as well.

          I’m not too concerned with photos at this time. I think if I wanted to include a photo in my journal, I’d figure out a way to have an additional “media” folder for each year of the journal and add my media in there, linked (using Markdown format) in the relevant journal entry.


  • Blogging from Command Line « Tokyotribeca July 12, 2014