Once I installed Apache2+MySQL5+PHP5.3 using MacPorts I wanted to start and stop the services without having to open a terminal window a run the commands myself. This can be achieved creating an AppleScript that executes the command and then saving it as an application.
Open the AppleScript editor (Utilities→AppleScript Editor.app) and write the command you want to run. I had to create 4 different applications because I wanted the start and stop applications for both Apache2 and MySQL5. As the commands must be run as an administrator I added at the end “with administrator privileges
” (the application will ask for the password):
do shell script "/opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper start" with administrator privileges
do shell script "/opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper stop" with administrator privileges
do shell script "/opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper start" with administrator privileges
do shell script "/opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper stop" with administrator privileges
It’s VERY IMPORTANT to clic the “Compile” button to be sure everything is correct and that the application is created. Now you only have to go to “File→Save…” and save it with the “Application” format.
0 Comments.