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: dr_turgeon on May 22, '03 01:32:54PM

The nice thing about this hint is the help one gets in making these kinds of simple script programs for OS X, using a real life example. A program that does it for you is mostly beside the point.

What would be a nice add-on to this hint would be a suggestion about getting compiled scripts to run instantly without the overhead of launching an app. I know script menu can, but what about from the dock?



[ Reply to This | # ]
Start and stop Apache from the dock
Authored by: robJ on May 22, '03 04:22:29PM
Save this as a stay-open application. When launched, it should run the script provided by the original poster. On subsequent clicks of the script's Dock icon, it will run the script again, without the need to go through the entire launch lag. I haven't tested the code but it should be close to what you want.
on run
	my toggle -- remove this if you don't want it to execute the code on launch.
end run

on reopen
	my toggle
end reopen

on toggle()
	do shell script "sudo /usr/sbin/apachectl stop"
	if result = "/usr/sbin/apachectl stop: httpd (no pid file) ¬
  not running" then
		do shell script "sudo /usr/sbin/apachectl start"
		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
	
	tell application "System Events" to ¬
		set visible of first application process whose frontmost is true to false
end toggle
     

[ Reply to This | # ]