ForceQuitter Tutorial

Back to Index


In this tutorial, we will create a menu item called ForceQuitter. This menu item will display a list of running processes, and will kill a process if it is selected from the menu.

In order to get a list of running processes, the command /bin/ps cx looks good. As for the menu title, let's just call it 'ps' (you can pick a different one if you like) and set title type to "Text only". The output from ps is space-formatted, so we'll want to use a monospace font: Courier is a good monospace font, but we don't want it to be too large, since ps generates a long list of output. At this stage, our window should look something like this:

Tapir ForceQuitter Settings

Try creating an application with these settings and run it. You'll get a menu in the top-right corner with the title 'ps' which shows a list of processes. However, selecting an item from the menu does nothing. We want to change this so that the process we select from the menu is terminated. For this, we'll need to do some scripting. Since Perl is my scripting language of choice, we'll use it in this tutorial, but you could achieve the same results with any of the scripting languages installed in Mac OS X, including shell, Python, Ruby, Tcl and PHP. Open a text file with your favourite text editor, and type in the following:


my $line = $ARGV[0];

# If line contains a process id and process name,
# we get the process id and send it a termination signal
if ($line =~ m/^*(\d+)\s/)
     my $pid = $1;
     kill(TERM, $pid);

Save this script as This short little script parses the string it receives as argument (namely the text in the menu item selected), retrieves process id from the string and then terminates the process in question.

To use this script in our program, we'll need to add it to the Tapir application. Press the [+] button next to the "Bundles Files" list, select your newly created script and add it to the list of bundled files. Once this is done, take a look at the Action section of the Tapir window. From the popup-menu, select "Feed to Program". A text field should appear right of the popup menu. Type in:


At this stage, our ForceQuitter menu should be ready to be created. Press the Create button and create the program where you want it. You should now have a fully functioning menu for forcequitting processes.