Ok the idea of this script is to
- Run at random times of the day
- Keep running for a number of weeks
- Make a recording from the line-in for a set time each time
My biggest problem is the “getTimesForToday” & “getATime” subroutines.
in particular the line
if timeList does not contain tempTime then
seems to always answer true no matter what. Is this the correct syntax for saying “if a item doesnt exist in the list then do stuff”??
the basic idea in my code is thus:
May be of some use to someone out there if I can get it working!
(the audio recorder app I use can be found here )
property timeList : {}
property numTimesaDay : 10
property currTime : numTimesaDay -- set it to the same so when first callled gets set up
property secondsToRecord : 2 -- number of seconds to record
property possHours : {9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
property possMinutes : {5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55}
-- MAIN:
on idle
try
log ("started")
set nowTime to do shell script "date +%H:%M"
log ("time Now: " & nowTime)
-- Is TimeList position at the end?
--if nowTime is "00:01" then
if currTime ? numTimesaDay then
-- Get the times for today
-- Stores the times in the timeList global
getTimesForToday()
display dialog ("got times for today!")
set currTime to 0
end if
-- Ok would now have timeList lets see if the current time is in the array
if timeList contains nowTime then
display dialog ("recording!")
set filename to do shell script "date +%x_" & currTime & "%H_%M" & ".mp3"
doRecord(filename)
currTime + 1
end if
on error errStr number errorNumber
display dialog (errStr)
end try
return 60
end idle
-- On QUIT
on quit
display dialog �
"Really quit?" buttons {"No", "Quit"} default button "Quit"
if the button returned of the result is "Quit" then
continue quit
end if
-- Without the continue statement, the
-- script application doesn't quit.
end quit
on doRecord(filename)
-- The actual script that does the record
tell application "Audio Recorder"
set the output format to MP3
set the quality to custom
set the MP3 bit rate to 32
set the MP3 mode to mono
set the next file name to filename
start recording
delay secondsToRecord
stop recording
end tell
end doRecord
-- This runs once a day to get the times it will run
on getTimesForToday()
-- note may break for 7,8,9 because should be 07,08,09
repeat with n from 1 to numTimesaDay
set tempTime to getATime()
log ("time " & n & " ->" & tempTime)
copy tempTime to the end of timeList
end repeat
end getTimesForToday
-- gets a Time that isnt in the list
on getATime()
set uniqTimeFound to false
repeat until uniqTimeFound
set tempHour to some item of possHours
set tempMinute to some item of possMinutes
set tempTime to tempHour & ":" & tempMinute
if timeList does not contain tempTime then
set uniqTimeFound to true
end if
end repeat
return tempTime
end getATime