I have an AppleScript I use to set up my AppleTV screen sharing, sometimes it gets stuck and I have to kill it to try again. So I'd like to write a script that kills any running scripts and then run the script again.
Problem is I can't work out a way to do it that doesn't kill the parent script itself.
I can see using
ps axc
that the file has the path
/Applications/Connect Screen Mirroring - Master Bedroom.app/Contents/MacOS/applet
So I tried using
set PID to do shell script "(ps ax | grep \"Connect Screen Mirroring - Master Bedroom\" | grep applet | awk '{print $1}')"
do shell script "kill " & PID
But that gives me the error
sh: line 0: kill: 88944 89410 89411: arguments must be process or job IDs
I think the problem is that the first script is giving me back a 2nd, and sometimes a 3rd, unexpected PID, so if I could just find a way to filter that out I might be good.
If I run just
set PID to do shell script "ps ax | grep \"Connect Screen Mirroring - Master Bedroom\" | grep applet"
I get back
"89474 ?? S 0:00.33 /Applications/Connect Screen Mirroring - Master Bedroom.app/Contents/MacOS/applet 89485 ?? S 0:00.00 sh -c ps ax | grep "Connect Screen Mirroring - Master Bedroom" | grep applet"
Best as I can tell, that second thing getting returned is the shell command itself.
Any suggestions on how to ignore that one? Or a better way to do this altogether?