Last active
December 15, 2015 11:59
-
-
Save giannis/5256701 to your computer and use it in GitHub Desktop.
This script starts mamp app without the need for a sudo password. In order to work you need to add a login entry on your keychain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#initial code from http://www.tech-otaku.com/local-server/starting-mamps-apache-mysql-servers-login/ | |
tell application "Finder" | |
# Check if the Apache or MySQL servers are already running | |
set apacheRunning to my ProcessRunning("httpd") | |
set mysqlRunning to my ProcessRunning("mysqld") | |
# If neither the Apache nor MySQL servers are already running... | |
if (not apacheRunning and not mysqlRunning) then | |
# get the user name and password using the security Terminal command | |
set theUserName to do shell script ("security find-generic-password -l \"MAMP\" | grep \"acct\" | cut -c 19-99 | tr -d '\"'") | |
set thePassword to do shell script ("security 2>&1 >/dev/null find-generic-password -gl \"MAMP\" | cut -c 11-99 | tr -d '\"'") | |
# Start MAMP's Apache server | |
do shell script "/Applications/MAMP/bin/startApache.sh &" password thePassword user name theUserName with administrator privileges | |
# Start MAMP's MySQL server | |
do shell script "/Applications/MAMP/bin/startMysql.sh > /dev/null 2>&1" | |
tell application "MAMP" | |
activate | |
delay 3 | |
end tell | |
tell application "System Events" to set visible of process "MAMP" to false | |
else | |
if (apacheRunning and mysqlRunning) then | |
set theMessage to "Both Apache and MySQL servers are" | |
else if apacheRunning then | |
set theMessage to "The Apache server is" | |
else if mysqlRunning then | |
set theMessage to "The MySQL server is" | |
end if | |
display alert "Local Server Environment" message theMessage & " already running." & return & return buttons {"OK"} default button 1 giving up after 50 as critical | |
end if | |
end tell | |
on ProcessRunning(processName) | |
set AppleScript's text item delimiters to "\\|" | |
set theExpression to processName as string | |
set AppleScript's text item delimiters to "" | |
set isRunning to every paragraph of (do shell script "ps -acwx -o command | grep -ix " & quoted form of theExpression & " || echo 'false'") | |
if isRunning contains "false" then | |
return false | |
else | |
return true | |
end if | |
end ProcessRunning |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment