10.4: Run postfix and other Unix services via Automator

Sep 28, '05 05:20:00AM

Contributed by: robelkin

Tiger only hintOn my PowerBook, I, like many others, have the postfix mail server running. In 10.3, there was a way of getting this mail server to start automatically upon login, but that doesn't seem to work anymore in 10.4, creating the annoying problem of having to open the Terminal and start it every time. This can be especially annoying when you think it's running and try to send an email and get an error as the server isn't running (I don't even bother with other SMTP services as it is too much hassle).

I decided I wanted to use the power of Automator to be able to run the server without having to open Terminal, etc. (it's a lazy man's way of doing things, I know, but this will allow for extensibility). Not knowing much about Automator, I searched this site and found this hint. I modified it slightly to be able to run the postcast mail server.

Basically, what you to do is as follows...

Open Automator and select the Finder option in the Library column, and drag the "Get Selected Finder Items" Action into the workflow area. Then choose the Automator option in Library, and select the the "Run Applescript" Action and drag it into the workflow area. Put this AppleScript into the text area:


on run {input, parameters}
  tell application "Terminal"
    activate
    if (the (count of the window) = 0) or ¬
      (the busy of window 1 = true) then
      tell application "System Events"
        keystroke "n" using command down
      end tell
    end if
    do script "sudo postfix start" in window 1
    do script "my_password" in window 1
  end tell
  return input
end run
Replacing the my_password bit with your actual administrator's password, as this will allow it to actually work!

Obviously, you can also use this script to start anything that needs starting in one go. For me that was the xampp system for Apache and PHP. To do so, simply put in more do script "unix command" in window 1 lines to run more things in the Terminal.

[robg adds: I believe this hint (note the fix in the comments) explains the standard way of enabling the server in 10.4 (though it also implies that it should already be set up to run 'on demand,' which should mean this hint is unnecessary). Three other hints cover related postfix/SMTP topics.]

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20050925143254121