0
My phone is dead and I don't have an alarm clock. Here was my solution (in Bash) to ensure I will wake up tomorrow morning
while [ 1 ]; do
TIME=$(date +'%H'):$(date +'%M')
echo $TIME
if [ $TIME == "06:15" ];then
osascript -e "set Volume 3"
open /Path/To/MyFavouriteSong.mp3
break
fi
sleep 58
done
This code works well (on Mac OSX 10.12.2
and as long as my computer does not go to sleep) but it feels somewhat silly.
It is unclear to me how does the CPU do to measure a certain time. I don't know if typically an alarm clock app tests every 58 seconds (or other amount of time closer but still shorter than one minute) if it is already time to sound the alarm or if there is some mechanism for the CPU to send a signal to the program at a specific time.
I see a close vote because "This question is not about computer hardware or software, within the scope defined in the help center.". Would the question be a better fit on StackOverflow or elsewhere? – Remi.b – 2017-02-05T21:45:40.790
Perhaps take a look at how cron daemons are implemented? – user1686 – 2017-02-05T21:47:56.663
The close vote was mine. This might be a borderline question, so I wanted to let potential closure be organic rather than post a comment and influence other voters. My reasoning is that programming questions are off-topic, and how any/all alarm clock programs work is overly broad. I don't really know which would be the best site for this, so I didn't suggest one. SO seems logical, but I'm not much of a user of that site so not sure how well this fits there. If this comment attracts feedback that this is on-topic here, I'll retract the close vote. – fixer1234 – 2017-02-05T22:10:42.577
Use a cron job. – DavidPostill – 2017-02-06T12:57:43.120
@fixer1234 IMHO the core of the question is how does the CPU do to measure a certain time? and I consider that on-topic. Some editing to focus the question would help though. – I say Reinstate Monica – 2017-02-06T18:14:48.770