Mit Hilfe des folgenden AppleScript-Schnipsels kann ein auf dem System installierter Apache- bzw. MySQL-Server gestartet oder gestoppt werden. Wer Interesse hat, kann den nachfolgenden Quelltext gerne unter Berücksichtigung der GNU AGPL weiterverwenden und/oder erweitern.
Dazugehörender Artikel: Mein Web-Sharing-AppleScript
-- This function returns "true" if the given process exists, otherwise "false".
-- @param string processName The name of the process to check.
-- @return boolean
on processExists(processName)
set returnValue to do shell script "ps -A | grep -v grep | grep -q " & processName & "; echo $?"
if returnValue = "0" then
return true
else
return false
end if
end processExists
-- Sets the correct value for the Apache button.
set apacheButton to "Start Apache"
if processExists("httpd") then
set apacheButton to "Stop Apache"
end if
-- Sets the correct value for the MySQL button.
set mysqlButton to "Start MySQL"
if processExists("mysqld") then
set mysqlButton to "Stop MySQL"
end if
-- Builds the main window.
set panel to display dialog "What do you want to do?" with title "Web Sharing" buttons {apacheButton, mysqlButton, "Close"} with icon 1
-- Tries to start or stop the choosen server.
if button returned of panel = "Start Apache" then
set command to do shell script "apachectl start; echo $?" with administrator privileges
else if button returned of panel = "Stop Apache" then
set command to do shell script "apachectl stop; echo $?" with administrator privileges
else if button returned of panel = "Start MySQL" then
set command to do shell script "sudo /usr/local/mysql/support-files/mysql.server start; echo $?" with administrator privileges
else if button returned of panel = "Stop MySQL" then
set command to do shell script "sudo /usr/local/mysql/support-files/mysql.server stop; echo $?" with administrator privileges
else
set command to "0"
end if
-- Displays a message if an error occured.
if (the last text item of command) is not equal to "0" then
display dialog "An error occured, please check your script." with title "Web Sharing" buttons {"Close"} with icon 2
end if