3

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
8
  • What's the script?
    – Tetsujin
    Oct 17, 2018 at 18:43
  • @Tetsujin I've added it to the question description.
    – Oleg
    Oct 17, 2018 at 18:50
  • 1
    OK, so you set it as a shell script - therefore it will wait until the app it launched quits, before moving on to the next line. I don't actually know how to prevent that.
    – Tetsujin
    Oct 17, 2018 at 18:52
  • 1
    I have some scripts that stay running for days, as the 'parent' of launched processes; at quit they then run further instructions to tidy up afterwards. I don't have them set as Services, so they don't annoy me by running that gear wheel.
    – Tetsujin
    Oct 17, 2018 at 18:58
  • 1
    Save the script as an App, launch by double-click. Mundane, but works for me ;) I'd wait to see if someone smarter than me knows how to make it step over, though - would be better long-term.
    – Tetsujin
    Oct 17, 2018 at 19:23

2 Answers 2

1

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.

2
  • 1
    how does it stop already running script ?
    – Ruskes
    Oct 17, 2018 at 22:16
  • 1
    You'd need a separate script to stop it.
    – TJ Luoma
    Oct 18, 2018 at 1:04
0

I would do:

  1. Open terminal
  2. Type ps aux|grep mysql
  3. get the PID of the script
  4. Type kill -s 9 #### where #### is the PID of the script

I would check to make sure that you don't kill the wrong process such as another mysql server.

2
  • you could use some smarts to check for the exact script you are running, but the above is very easily scriptable.
    – Deesbek
    Oct 18, 2018 at 3:58
  • what is -s 9? Is is the same as -9?
    – Oleg
    Oct 25, 2018 at 17:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .