Skip to content

Instantly share code, notes, and snippets.

@connordavison
Last active October 3, 2015 15:25
Show Gist options
  • Save connordavison/0a613ec8a85a6276e57a to your computer and use it in GitHub Desktop.
Save connordavison/0a613ec8a85a6276e57a to your computer and use it in GitHub Desktop.
Execute command if idle
#!/bin/bash
#
# Execute a command if the user is idle for a specified period of time
# Requires: xprintidle
# Usage: if-idle IDLE_MIN IDLE_COMMAND [NOT_IDLE_COMMAND]
#
IDLE_MIN=$1
IDLE_TIME=$(xprintidle)
IDLE_COMMAND=$2
NOT_IDLE_COMMAND=$3
[ "$IDLE_MIN" -lt "$IDLE_TIME" ] && $IDLE_COMMAND || $NOT_IDLE_COMMAND;
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment