On Apr 03, 2013, at 14:44, Alex Zavatone < email@hidden> wrote: Here's a little test script you can paste and run. The log returns true whether Safari is in the foreground or the background on my system. if you comment out the ≠, the PID of the Safari process and the elapsed CPU time is still displayed.
______________________________________________________________________
Hey Alex,
I'm not doing much checking here (and haven't tested much).
The script assumes it starts with an on-state, and suspends the processes if they exist.
On the next run it toggles them back on.
STAT == 'T' is a suspended process.
-------------------------------------------------------------------------------------------
set AppleScript's text item delimiters to tab set procList to paragraphs of (do shell script "ps axc -o pid,stat,comm | awk '/Safari|WebKitPluginAgent|WebProcess/ { print $3\" \\t\"$2\" \\t\"$1}';" )
repeat with i in procList if i starts with "Safari" then set _pid to last text item of i set _state to text item 2 of i if _state = "T" then do shell script ("set +o posix; kill -SIGCONT " & _pid) else do shell script ("set +o posix; kill -SIGSTOP " & _pid) end if end if
if i starts with "WebKitPluginAgent" then set _pid to last text item of i set _state to text item 2 of i if _state = "T" then do shell script ("set +o posix; kill -SIGCONT " & _pid) else do shell script ("set +o posix; kill -SIGSTOP " & _pid) end if end if
if i starts with "WebProcess" then set _pid to last text item of i set _state to text item 2 of i if _state = "T" then do shell script ("set +o posix; kill -SIGCONT " & _pid) else do shell script ("set +o posix; kill -SIGSTOP " & _pid) end if end if end repeat
set AppleScript's text item delimiters to ""
-------------------------------------------------------------------------------------------
I think pkill and pgrep are part of Mountain Lion, but I won't bother to fire up a pristine system to find out. They might be part of Xcode's cli tools though.
-------------------------------------------------------------------------------------------
# INFO pgrep -i -d' ' "Safari|WebKitPluginAgent|WebProcess"
# SUSPEND S=$(pgrep -i -d' ' "Safari|WebKitPluginAgent|WebProcess"); set +o posix; kill -SIGSTOP ${S};
# CONTINUE S=$(pgrep -i -d' ' "Safari|WebKitPluginAgent|WebProcess"); set +o posix; kill -SIGCONT ${S};
# INFO ps auxc | awk '/USER|Safari|WebKitPluginAgent|WebProcess/ { print }';
-------------------------------------------------------------------------------------------
Surely there's a way to get pkill itself to execute the signals, but I'm not going to fool with it any further at the moment.
I'd probably run this critter manually rather than setting up a process-watcher - and of course there's always AppTamer.
-- Chris
|