Search code examples
macoskeyboard-shortcutsguard

Pause guard using a system wide keyboard shortcut (OSX)?


I use the phantastic Guard gem to do BDD in Rails. It's great that it executes all my specs etc. automatically after changing a file, but there are times where I don't want them to run immediately, and I pause Guard by pressing P in the console. But after several times, this becomes tedious, and it would be nicer to have a system wide keyboard shortcut or something to tell Guard to pause/unpause.

Anybody has an idea on how to accomplish this? Thanks.


Solution

  • I have an idea, but I'm unable to test if it works, since I enjoy my holiday and the data plan I quite expensive, so I try to limit my Internet usage.

    You can execute a shell script like it's described under Fast User Switching/Apple Menu?. The script itself could send a signal to Guard to start/stop the listener.

    Update:

    The following script has been developed in Guard issue #303.

    local FILE = "/tmp/.guardpaused"
    if [ -f FILE ]; then
      ps -ef | grep -i guard | grep -v grep | awk '{print $2}' | xargs kill -USR2
      rm FILE
      echo "Unpaused files modification listening."
    else
      ps -ef | grep -i guard | grep -v grep | awk '{print $2}' | xargs kill -USR1
      touch FILE
      echo "Paused files modification listening."
    fi