Keep your work chat active and your computer awake while working from home

With many of us still working from home (at least part-time), work chat apps have overtaken email as the primary means of communication. Many of these apps, such as Microsoft Teams and Slack, also show how long you've been inactive.

For most of us, a chat app showing you're inactive doesn't really matter; however, for some, bosses and coworkers start to make assumptions 🙄.

There are solutions all over the Internet suggesting placing something heavy onto your keyboard in an open document to continuously insert text, or even placing your mouse on a moving object.

I've got a much simpler solution for you to keep your work chat active and your computer awake while working from home.

Usage

First, you'll need to install cliclick. The easiest way is via Homebrew:

$ brew install cliclick

Next, copy the function below and save to your .zshrc or .bashrc (etc.) to make it available on your command line.

#
# Move the mouse to prevent computer from going idle.
#
# Accepts a number as the first argument that indicates the
# number of seconds between mouse movements. Defaults to 4.5 minutes.
function keepawake() {
  if ! [ -x "$(command -v cliclick)" ]; then
    echo "Error: cliclick is not installed." >&2
    echo "You can install from Homebrew:"
    echo "$ brew install cliclick"
    return
  fi

  if [ -z $1 ]; then
    # Default delay of 4.5 minutes
    DELAY=270
  else
    DELAY=$1
  fi

  while true; do
    cliclick -r -e 200 m:+100,+100
    sleep $DELAY
  done
}

To run the function, simply call it and provide it with a directory name:

$ keepawake

Your mouse will now move slightly every 4.5 seconds, keeping your computer awake. When you're finished, just stop the command with Ctrl + C.