can i make my mac say hi to me when it wakes up?

I was wondering if and how it was possible to make my mac say hello to me when it woke from sleep or when i logged on. Maybe even specify morning, afternoon, and evening? Thanks for the help!

iMac G5 with iSight, Macbook Pro Core2 Duo, Mac OS X (10.4.8)

Posted on Feb 4, 2007 5:37 PM

Reply
7 replies

Feb 4, 2007 8:16 PM in response to Ryan Malone

> do have one for question though. Is it possible to get it to say something different depending on what the time of day it is?

Sure, there are several ways of doing that, depending on what you want to do.

For one, if you want a custom sentence, either write multiple handlers (e.g. on doMorning(), doAfternoon(), and doEvening()), then call them separately from the idle handler (or cron), or you could add logic to the 'sayHi()' handler, like:

<pre class=command>on sayHi()
-- this returns a number (0 - 23) indicating the current hour:
set currentHour to hours of (get current date)
if currentHour < 12 then
say "Good morning"
else if currentHour < 17 then
say "Good afternoon"
else
say "Good evening"
end if
end sayHi</pre>

Feb 4, 2007 6:17 PM in response to Ryan Malone

It's trivial to get AppleScript to talk to you:

<pre class=command>say "hi me"</pre>

What's harder is the scheduling.

Login is easy enough - just save the script as an application and drag the app to your Login Items (in System Preferences -> Accounts). Now it'll launch whenever you log in.

It's also not hard to get the script to run on a timed schedule - probably easiest to use cron (the unix scheduling daemon). In terminal, run:

<pre class=command>crontab -e</pre>

and add something like:

<pre class=command>0 9,14,20 * * * osascript -e 'say \"Hi Ryan\"'</pre>

(check man crontab for the first 5 fields which manage cron's scheduling - for now know that the above script will run at 9am, 2pm and 8pm)

The trickiest of all is the 'wake from sleep' option. There's no built-in way of running a script when the system wakes. The best solution I can suggest is a stay-open script that periodically checks the time with a heartbeat (e.g. once per minute). As soon as it hears a heartbeat that's more than 1 minute since the previous one you can assume you've been asleep and therefore do your thing, like:

<pre class=command>global lastRunTime

on sayHi()
say "Hi me"
end sayHi

on run
set lastRunTime to (get current date)
end run

on idle
-- has it been more than 65 seconds since we last run?
-- (I use 65 seconds to give a little slack time)
if (get current date) > (lastRunTime + 65) then
-- we missed a heartbeat, so assume we've been sleeping
my sayHi()
end if
-- reset the lastRunTime
set lastRunTime to (get current date)
-- and come back in 60 seconds time
return 60
end idle</pre>

Feb 4, 2007 7:13 PM in response to Ryan Malone

WOW!! it worked... i thought i would try it and it worked... amazing. How do you guys think of these things? i think i have most of the script figured out so im going to personalize it but wow. Thanks so much for your help. i do have one for question though. Is it possible to get it to say something different depending on what the time of day it is? again, thanks for your help and time!-Ryan

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

can i make my mac say hi to me when it wakes up?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.