A more generic solution based on the answer by Frank Schmitt:
!/usr/bin/bash
USAGE="USAGE: $0 OPTION_NAME ON_STATE OFF_STATE"
OPTION_NAME=$1
ON_STATE=$2
OFF_STATE=$3
if [[ "$#" != 3 ]]; then
echo $USAGE
exit 1
fi
if [[ `tmux show-option -w | grep "$OPTION_NAME $ON_STATE"` ]]; then
OPTION_VALUE=$OFF_STATE
else
OPTION_VALUE=$ON_STATE
fi
tmux display-message "monitor activity: $OPTION_NAME $OPTION_VALUE"
tmux set-option -w $OPTION_NAME $OPTION_VALUE > /dev/null
The script takes the name of the option, the on value and the off value. Not very well tested but works for simple cases like:
PATH_TO_SCRIPT_ABOVE monitor-activity on off
In your .tmux.conf:
bind-key <SOME_KEY> run-shell "tmux_toggle_option monitor-activity on off"