MacID for OS X Extension – Set Slack Away

Here’s a small AppleScript extension which will set you as away on Slack when your Mac sleeps (if Slack is running):

on slackIsRunning()
  set isRunning to false
  tell application "System Events"
    set isRunning to (name of processes) contains "Slack"
  end tell
  return isRunning
end slackIsRunning

on setAsAway()
  activate application "Slack"
  tell application "System Events"
    tell process "Slack"
      keystroke "/away "
      keystroke {return}
    end tell
  end tell
end setAsAway

if slackIsRunning() then
  setAsAway()
end if

It works best if you drop it into MacID’s “onSleep” directory rather than “onLock”. It’s also worth noting that typing /away ┬áin Slack while you’re away will set you as active, so if you’re already set as away this script will do the opposite!

For more information about extending MacID with AppleScript check this post out.

Leave a Reply

Your email address will not be published. Required fields are marked *