Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Start and stop Apache from the dock' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Start and stop Apache from the dock
Authored by: discordantus on May 22, '03 04:36:03PM
If you aren't too keen on changing the sudoers file to not require your password, you can let applescript take care of the auth for you:


do shell script "/usr/sbin/apachectl stop" with administrator privileges
if result = "/usr/sbin/apachectl stop: httpd (no pid file) not running" then
	do shell script "/usr/sbin/apachectl start" with administrator privileges
	display dialog "Apache Started" with icon 2 buttons ¬
		{"OK"} giving up after 1
else
	display dialog "Apache Stopped" with icon 2 buttons ¬
		{"OK"} giving up after 1
end if

If you want, you can throw your password into the script and it won't ask you for it:

do shell script "/usr/sbin/apachectl stop" password "mypassword" with administrator privileges

On a side note, I had a problem with the line break in the second statement, after "(no pid file)"... I had to remove it to get the script to work.

[ Reply to This | # ]

Start and stop Apache from the dock
Authored by: Graff on May 22, '03 08:14:55PM

On a side note, I had a problem with the line break in the second statement, after "(no pid file)"... I had to remove it to get the script to work.
Right, that's because the line break occurs within a quoted string. In order to break lines in code in the middle of a quoted string you need to make two strings with a concatenation and the line break in between them.

Original lines:
if result = "/usr/sbin/apachectl stop: httpd (no pid file) ¬
not running" then
do shell script "sudo /usr/sbin/apachectl start"

Corrected lines:
if result = "/usr/sbin/apachectl stop: httpd (no pid file)" & ¬
"not running" then
do shell script "sudo /usr/sbin/apachectl start"



[ Reply to This | # ]