|
From: Todd N. <osx...@ya...> - 2005-02-28 07:35:33
|
With RSD, or carpal tunnel... It's obvious important
to rest regularly,
particularly those of us that like to hack for days at
a time.
OSX comes with 'leave' a nice little program but
without the
features wanted. This script is a leave+ kinda thing,
I added
a bunch of functionality, so read the code. The
qtplay external is
required, and I renamed it after I compiled it (google
for qtplay,
download, compile, intall in /usr/bin/ or
/usr/local/bin or ~/bin)
installed it. OSX as far as I can tell does NOT come
standard with
a quicktime sound player of any kind. But this is
good, for the
qtplay is a superb example of hacking, works great,
free, source
and you get to learn about the Core stuff it uses.
That all said, here is the timetoleave replacement I
made using
Sensetalk as the core of the solution.
todd$ cat timetorest
#! /usr/bin/st
# a replacement for the 'leave' command, this one will
make statements
# and allow you to choose a sound or sentence to say,
or both.
# alarms will go off at 5 mins before, and of course 1
min and finally
# the alarm time.
# st timetorest -s time -r mins -say words -v name
-sound path -w bool -warnlist list
set the clockFormat to "24 hour" -- makes the long
time "xx:yy:zz" and the time "xx:yy"
put parseParms(the params, "") into opt -- no rules
yet...
if opt's s is EMPTY or not isaTime(opt's s) or s is
not in the keys of opt then put the short time + 60
minutes into opt's s
if opt's r is EMPTY or opt's r is not a number or r is
not in the keys of opt then put 60 into opt's r --
default 1 hour breaks
if opt's v is EMPTY or opt's v is not in
availableVoices() or "v" is not in the keys of opt
then put "Victoria" into opt's v -- Default nice
voice
if opt's w <> true and opt's w <> false or w is not in
the keys of opt then put true into opt's w
if opt's say is EMPTY or say is not in the keys of opt
then put "Time to take a break" into opt's say --
default say "Time to take a break"
if opt's sound is EMPTY or opt's sound is not a file
or sound is not in the keys of opt then put
"/System/Library/Sounds/Submarine.aiff" into opt's
sound -- system sound
if opt's warnlist is EMPTY or warnlist is not in the
keys of opt then put (5,1) into opt's warnlist --
could use this to loop until done
sort opt's warnlist numerically descending
put opt
-- a list of times to play a warning before we
actually tell the person to rest/get up.
repeat with each item in opt's warnlist
put opt's s - (it) minutes into npTime --
next play time.
repeat until the time > time(npTime)
wait 1 seconds
end repeat
if opt's w then -- pl/say if told to do so.
shell("play " & opt's sound)
shell("say -v " & opt's v && it & "
minutes until rest time.") -- ... voice.
end if
end repeat
wait until the time > opt's s
if opt's w then
play opt's s
shell("say -v " & opt's v && items 1 to -1 of
opt's say)
end if
# Test invocation:
# st ./paramParser -a 1 2 3 -b 2 -c 3 -Dash Boulder
-Super man -c 10 11
#
# Current (bogus) output:
# (a:("1","2","3"), b:("2"), c:("3"),
Dash:("Boulder"), Super:("man"))
#
to parseParms params, rules -- 'rules' support is
coming real soon now :)
put a new object into obj
delete word 1 of params -- toss the handler
name
set the itemDelimiter to "-"
delete item 1 of params -- assume params
starts with '-', all filenames at end of CLI
repeat with each item option of params
set the itemDelimiter to ","
put deQuote(item 1 of option) into key
-- the key
put () into vals
repeat with n = 2 to number of items
in option
get deQuote(item n of option)
-- the value
if it is empty then next
repeat -- likely end of option list
insert it after vals
end repeat
put obj plus properties ((key):(vals))
into obj -- why doesn't merge|replace existing values
of key?
end repeat
return obj
end parseParms
to deQuote string -- Removes all leading space
and quotes of a string, returns that string
repeat length of string times -- do leading
junk and ...
if first char of string is not in
quote & space then exit repeat
delete first char of string
end repeat
repeat length of string times -- ... do junk
in trunk
if last char of string is not in quote
& space then exit repeat
delete last char of string
end repeat
return string
end deQuote
to availableVoices
get shell("ls -1
/System/Library/Speech/Voices/ | cut -d\. -f1")
put () into voices
repeat with each line n in it
insert word 1 of n after voices
end repeat
return voices
end availableVoices
-- ugly! :)
to isaTime aTime
if char 3 of aTime is ":" then delete char 3
of aTime
put false into hValid
put false into mValid
get chars 1 to 2 of aTime
if it >= 0 and it < 24 then put true into
hValid
get chars 3 to 4 of aTime
if it >= 0 and it < 60 then put true into
mValid
if hValid and mValid then return chars 1 to 2
of aTime & ":" & chars 3 to 4 of aTime
else return false
end isaTime
__________________________________
Do you Yahoo!?
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250
|