Using an AppleScript to kill an AppleScript
Here is how I'd do it:
In Terminal:
kill $(ps ax | awk '/[C]onnect Screen Mirroring - Master Bedroom/{print $1}')
Using the do shell script
command in AppleScript:
do shell script "kill $(ps ax | awk '/[C]onnect Screen Mirroring - Master Bedroom/{print $1}'); exit 0"
Using awk
eliminates the need to pipe to grep
twice while allowing it to return only the value of the first column of ps
output, which is the PID
, and by placing square braces around the first character [C]
it isolates the output to the occurrence being looked for, not what's generated by the awk
command itself.
Using command substitution, $(...)
, it returns only the PID
to the kill
command.