MacOS – How to force quit an AppleScript script launched from toolbar

applescriptmacos

I have an AppleScript script (to launch MySQL) that I run from the AppleScript toolbar menu. It does the job (launches MySQL), however the script doesn't seem to be quitting. And the gearwheel in the toolbar keeps rotating.

Gearwheel keeps rotating

When clicking the gearwheel I can click the 'x' close button for that script, but it does nothing. There are no frozen processes in Activity Monitor.

How can I "force quit" that script?

P.S. Someone asked what's the script, here it is:

do shell script "sudo /usr/local/mysql/support-files/mysql.server start" with administrator privileges

Best Answer

Ok, first off, when you are using AppleScript’s “with administrator privileges” you should not use sudo

Second, you need to send the job into the background if you want the AppleScript to finish.

The easiest way of doing that is to put the command in a shell script, like so:

#!/bin/zsh -f

/usr/local/mysql/support-files/mysql.server start &|

exit 0

(Note the &| at the end of the line. That tells the process to go into the 'background')

Save those 3 lines to a file named something like /usr/local/bin/start-mysql-server.sh and then do

chmod 755 /usr/local/bin/start-mysql-server.sh

to make it executable.

Finally, change your AppleScript to

do shell script "/usr/local/bin/start-mysql-server.sh" with administrator privileges

and it should launch and then the gear should disappear.