I designed a small automator application that helped me to launch and finish apache ( another for mysql), to ensure that I do not must see the terminal and get it done ( yes I am that lazy).

now this is actually the applescript I use for this:

on run {input, parameters}

set apache2state to (do shell script "/bin/ps -arx |/usr/bin/grep apache2 |wc -l")
repeat until apache2state does not start with " "
    set apache2state to text 2 thru -1 of apache2state
end repeat
if apache2state is equal to "3" then
    do shell script "/opt/local/bin/port load apache2" with administrator privileges
    do shell script "/opt/local/bin/port unload apache2" with administrator privileges
end if

end run

This works, aside from the truth that I am really evaluating to integer values which are in accordance with the amount of processes that apache is running.. therefore it is not necessarily reliable.

It is possible to better method to test if apache (and mysql, I've another script likewise) is running. Issue is that when they're turn off the spend command will return an integer value likewise ( and not simply single for that grep process..)


EDITED to specify thatthe solution up here labored badly since the grep would return any demonstration of the apache threads and then any other process nevertheless apache ( like tail -r /var/log/apache2/error.log for example).

The running condition of the service could be examined using the following command:

/sbin/service --test-if-configured-on "org.apache.httpd"

Nevertheless this may not work with services installed with MacPorts.

Also begin to see the response to the this question.

Because the command service is deprecated under Snow Leopard, you are able to alternatively use launchctl to get the running condition of the service. The command could be invoked from AppleScript within the following way:

    do shell script "/bin/launchctl list | grep -q org.apache.httpd" with administrator privileges
    set apache2Running to true
on error
    set apache2Running to false
end try