1 | (* Applescript to stop/start MySQL Server app |
---|
2 | Author: Craig Treleaven, ctreleaven at cogeco.ca |
---|
3 | Modified: 2012Jul13 |
---|
4 | |
---|
5 | NB - if mysqld is running, we only stop it if it was launched under launchd |
---|
6 | *) |
---|
7 | set mysqld to " not running on this machine." |
---|
8 | set mysqlButton to "Donno" |
---|
9 | set newline to " |
---|
10 | " |
---|
11 | set indent to space & space & space & space |
---|
12 | set myResult to "" |
---|
13 | |
---|
14 | repeat until (myResult contains "Close") |
---|
15 | set processes to do shell script "ps -Ac" |
---|
16 | if the processes contains "mysqld" then |
---|
17 | set mysqld to " running." |
---|
18 | set mysqlButton to "Stop MySQL" |
---|
19 | else |
---|
20 | set mysql to " not running." |
---|
21 | set mysqlButton to "Start MySQL" |
---|
22 | end if |
---|
23 | |
---|
24 | set myResult to display dialog "Simple tool to start and stop the MySQL database server" & newline & newline & "Currently... " & Â |
---|
25 | newline & newline & indent & "MySQL server is" & mysqld  |
---|
26 | with icon note with title  |
---|
27 | "Stop/Start MySQL Server" buttons {mysqlButton, "Close"} Â |
---|
28 | default button "Close" -- cancel button "Close" |
---|
29 | set myResult to button returned of myResult |
---|
30 | if myResult contains "Start MySQL" then |
---|
31 | do shell script "sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist" with administrator privileges |
---|
32 | delay 2 -- a little time to start up |
---|
33 | else if myResult contains "Stop MySQL" then |
---|
34 | if ((do shell script "sudo launchctl list" with administrator privileges) contains "mysql5") then |
---|
35 | do shell script "sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql5.plist" with administrator privileges |
---|
36 | else |
---|
37 | display alert " MySQL Server appears not to have been started in the normal fashion. Unable to shut down." message "Was mysqld started directly from a command line session?" as warning |
---|
38 | end if |
---|
39 | set myResult to "Close" |
---|
40 | end if |
---|
41 | end repeat |
---|