#!/usr/bin/perl -T ## 2008-11-14 Rob Mahurin ## Instructions: ## 1. save to some folder e.g. desktop ## 2. open /Applications/Utilities/Terminal.app ## 3. in a terminal, say ## $ cd "/Users/you/Desktop" # (or wherever you put it) ## $ chmod +x ./checkidle ## $ ./checkidle >> datafile.txt & ## $ exit ## 4. check datafile.txt to see the name of the frontmost application. ## updates added every 30 seconds use strict; use warnings; use POSIX qw/strftime/; my @path = qw[ /bin /usr/bin /sbin /usr/sbin ]; $ENV{PATH} = join ":", @path; sub idle() { my @ioreg = grep /idle/i, qx/ioreg -c IOHIDSystem -S/; my ($idlens) = reverse split /\s+=\s+/, shift @ioreg; return $idlens/1e9; } sub frontmost() { my $script = 'set myapp to name of (info for (path to frontmost application))'; open SCRIPT, "echo '$script' | osascript |"; chomp(my @out =