MacOS – Any way to force command line terminal to control a Mac

macmacosterminal

I'm experimenting a little with Automator at the moment and often get stuck with some pre-recorded automation running very slowly while the whole Mac (an 2010 iMac in my case) doesn't respond to any input – either by keyboard or mouse.

For now I connect via SSH from another machine and issue a killall Automator to get controls back.

Is there any solution available which enables me to halt / freeze a Mac and issue commands using a terminal?

Best Answer

You could also run a "deadman's switch" app: have a script (maybe an Applescript) running when you start the Automator testing. After five minutes (or however long the Automator setup should take), it should display a dialog asking if you have control back this dialog would have a timeout (of 30 seconds or so), after which, it would try to kill the Automator process.

Example code:

delay 300

display dialog "Can you use the computer yet?" buttons {"Yes!", "No ?"} default button 1 giving up after 30

set retval to (the result)

set gaveUp to (gave up of retval)
set theText to (button returned of retval)

repeat while gaveUp or theText is not "Yes!"
    set randomNumber to (random number from 1 to 65535)
    do shell script "kill -9 " & randomNumber

    display dialog "Can you use the computer yet?" buttons {"Yes!", "No ?"} default button 1 giving up after 30

    set retval to (the result)

    set gaveUp to (gave up of retval)
    set theText to (button returned of retval)
end repeat

(Note that this code, instead of killing Automator, kills a random process. This is probably not a good idea, but I'm not sure exactly what you need to kill, and I thought it'd be fun. I've not actually tested that particular bit of code.)