20 February 2014

Taking a shortcut

Last week, someone asked me if there was a key command to activate the Witness alarm on your Mac. There isn’t, but you can easily create one using AppleScript and Automator:

You will first need to create a service in Automator that switches the alarm on:
  • Launch Automator (in Applications)
  • Choose “Service” from the template menu
  • Select “no input” in the “Service receives” drop-down menu

  •  With Actions selected in the left-hand toolbar, type “run Applescript” in the search field

  • Drag the “Run AppleScript” action to the main view
  • Replace (* Your script goes here *) with the following script:
tell application "WitnessUserAgent" to activate

This will activate the alarm on all your Macs.
(For a script that will deactivate the alarm, you can replace "activate" by “deactivate”.)

  • Choose File > Save
  • Give a name to this service (for example “Activate Witness”)
Now you can assign a keyboard shortcut to this service:
  • Open System Preferences > Keyboard
  • Go to the Shortcuts tab
  • Select “Services” in the left-hand menu
  • Scroll down until you find your service
  • Select the service and click “add shortcut”
  • Press the keys which you would like to use as the shortcut for Witness
  • Make sure the box next to the shortcut is checked

You're all set!