Multi-threaded AppleScripting for multi-core machines (kinda)

I have just managed to multi-thread (kinda) AppleScript, for big text-manipulation jobs.

I have an enormous text file that I need to manipulate fairly regularly. The script used to take an hour to run on my 8-core Mac Pro. It seemed a shame that the other seven cores were doing nothing. I faced two problems:

1- getting multiple instances of Tex-Edit Plus to run
2- calling several scripts at once.

The first one was easy - I just copied Tex-Edit Plus five times, for six versions in total. I named each with its number. I gave them each an icon including a number, so that I could keep track of them.

I then needed six copies of the script (each the same, but targetting a different version of Tex-Edit Plus, and working on a 1/6th chunk of the whole document) and a way of getting them all to start at once. In the shell script below, each line executes, then runs in the background. Here is an example of the shell script that calls each AppleScript. I call it “”

The AppleScript needs to be duplicated, and each version call it’s own copy of Tex-Edit Plus. “Osascript” is used to call (or run) AppleScripts. The ampersand backgrounds each task once it’s started.

Below is an example of one of these scripts. All this testing example does is take a while to execute, and work one core fairly hard:

The result is that I can break my text file into six parts - one for each iteration of Tex-Edit Plus - and saturate six cores at once (I need one free for iTunes :). With this particular test file, executing one script took 8 seconds. Executing all six took 10 seconds.

As you can see, six of the cores are all going for it.

In order to have a bit of feedback, I call the shell script from another AppleScript (I know…)

I’m sure there are more elegant ways of doing this, but this one works for me for now. All comments / questions / flames welcome.

Model: Mac Pro
Browser: Firefox 3.0
Operating System: Mac OS X (10.5)


parsing text with AppleScript using a text editor is quite slow because sending Apple Events is always expensive.
Instead of wasting more time to split the text files and run multiple scripts I’d prefer a more effective parsing routine
with sed or a perl script.

Hi SefanK
Wow. I was hoping that my post would scare up better ways of doing things, because using the GUI for text manipulation has always seemed kludgy. I was searching for faster text editors that support multi-threading and grep, but it turns out that I was asking the wrong question.

sed is amazing! It’s 50-100 times faster than what I was using. With a bit of perl to handle the fine work, I should have everything I need. Thanks for the tip - I see a new learning curve ahead!