Macotron

macotron.idle

Read how many seconds have passed since the last keyboard, mouse, or trackpad input, and get an event when the user goes idle or comes back.

// Pause music after five minutes away.
macotron.idle.setThreshold(300);

macotron.on("system:idle", () => {
  if (macotron.media.nowPlaying().playing) macotron.media.playPause();
});

Idle time

seconds(): number

Seconds since the last input event from any keyboard, mouse, or trackpad. The value has a fractional part.

setThreshold(seconds: number): void

Sets how many seconds without input count as idle. The default is 60. There is one threshold for all plugins, so the last plugin to call this sets it for everyone.

Events

Macotron checks the idle time every 5 seconds, so an event can arrive up to 5 seconds after the threshold is crossed. Neither event has a payload.

system:idle

Fires once when the idle time reaches the threshold.

system:active

Fires on the first check after input resumes. It means that idle ended, not that the Mac woke from sleep; listen for system:wake for that.

macotron.on("system:active", () => {
  macotron.notify.toast("Welcome back");
});

See also