Task Scripting Guide

KosmicTask Help

Task Scripting Guide

KosmicTask is a tool for creating and sharing script powered tasks on OS X. In general a task performs a routine operation such as one of the following:

  • Convert a Word document file into HTML.
  • Turn down the volume on a mac playing iTunes in another room.
  • Find out what a router’s external IP address is.

Each of these operations can be achieved by issuing commands to OS X and a task simply contains a number of such commands. When a task is run KosmicTask prompts the user for any inputs that the task requires. The task then executes its commands and returns any results to the user. KosmicTask includes a range of predefined example tasks and a wide selection of task templates that serve as starting points for new tasks. 

Getting Started with Commands

The simplest way to send commands to the mac is to use the Terminal application. So, for example, we can convert a Microsoft Word format document into html by typing the following command into the Terminal:

textutil -convert html "/Users/Mugginsoft/Documents/My Word Document.doc"

Executing this command will create an html file called MyWord.html. 

We can automate this operation by saving the above command into a file. Then all we have to do is run the file whenever we want to convert our file. The Terminal application sends commands to the Bash shell by default. The shell accepts the commands and executes them. So the above is an example of a simple Bash script.

Scripting is an extremely powerful means of controlling your mac and KosmicTask makes it easy to create, organise, execute and share such scripts as tasks.

Scripting and All That

The first thing to say about scripting is that it is fun! You don’t have to be a programmer to have a go at using KosmicTask to create script powered tasks. There are lots of scripting resources available on the Internet and KosmicTask makes it easy to use an existing script as a starting point.

Scripts can be very simple, like the one above, or much more complex. OS X also supports a wide range of different scripting languages each of which has different characteristics. KosmicTask also includes a number of additional scripting languages.

So let’s have a go at creating a task!

Creating a Task

The objective of our task is to save an iWork '09 Pages document as HTML. This version of Pages can export documents as PDF, Word, rich text, plain text and ePub but not as HTML.

A bit of searching on the Internet reveals that a workable solution is to save the Pages document as a rich text (RTF) file and convert the RTF document to HTML using the textutil OS X command. Now we don't know anything about the textutil command but an Internet search for "textutil" leads us to the Apple manual page for this command. Here we can see what options are available for our command (we can also get to the manual page by typing "man textutil" into the Terminal app).

We want to convert a file so our basic command looks something like:

textutil -convert html "/Users/Jonathan/Documents/My Pages document.rtf"

Note that our file name contains a space. Hence we need to enclose it in quote marks. A bit of experimenting with this command reveals that any images in our Pages '09 document are exported as PDFs, which doesn't make them suitable for embedding with an HTML page. Hence our script is really only useful for converting documents that do not contain images.

Now that we know what we are doing it's time to create our task:

  • First download and install KosmicTask.
  • Open the application and click the Admin button.
  • Click the New button in the toolbar (or menu File - New Task).

A task edit window will open to allow us to define, edit and test our task. 

Edit window

In general we need to enter at least 4 pieces of information to define our task:

  • A Name. "Convert My Text File" sounds good to me.
  • A Script type. In this case we want to select Bash shell.
  • A Group to put our task in. I chose "My File Utilities".
  • A Short Description. Something like "Convert a text file to HTML".

That's it. Time to enter our script.