(* ahpctl - records a buffer of audio while screensaver runs. by 31d1 djbidi@gmail.com version 0.2 scpt requires Audio Hijack Pro Setup: set the following variables to min recording time in seconds *) set minTime to 30 set outFileName to "~/Desktop/ahpctl.mp3" (* save as a script in ~/Library/Scripts Use When launched, will wait until it detects the screensaver is running While screensaver runs, uses AHP to record in chunks of minTime, removing every (n - 2)th chunk. When screensaver stops, concatenates the chunks, leaves a wav file on your Desktop, and exits. You get the last 2minTime of ambient audio with at least minTime recorded before screensaver stopped. *) -- repeat repeat while ((do shell script "ps -c -U $(whoami) | awk '/ScreenSaver/'") = "") delay 10 end repeat tell application "Audio Hijack Pro" activate tell application "System Events" set visible of process "Audio Hijack Pro" to false end tell set theSession to make new audio device session at end of sessions set input device of theSession to (first audio input whose name is "Default System Input") set output device of theSession to (first audio output whose name is "Silence Output") set recording format of theSession to {encoding:MP3, bit rate:192, sample rate:44.1, channels:Stereo, style:CBR} set output folder of theSession to "/tmp/" set output name format of theSession to "ahpctl%index" set x to 0 start hijacking theSession start recording theSession delay minTime repeat until ((do shell script "ps -c -U $(whoami) | awk '/ScreenSaver/'") is "") split recording theSession delay minTime set x to (x + 1) if (x > 1) then if (x < 11) then set theFile to "/tmp/ahpctl0" & (x - 1) & ".mp3" else set theFile to "/tmp/ahpctl" & (x - 1) & ".mp3" end if do shell script "rm " & theFile end if end repeat stop recording theSession stop hijacking theSession delete theSession quit end tell do shell script "cat /tmp/ahpctl*.mp3 > " & outFileName & " ; rm /tmp/*ahpctl*" -- end repeat