I am trying to write a script that displays a dialog that says either good morning or good night etc. Depending on the current time. but I don’t know how to. Please help me!!!
Hmmm, that was fun
That’s sweet, Greg! This is an excellent example of using the shell to simplify a script.
– Rob
I just happened to be playing with the date thingies today. Fun stuff, ya know…
Just to take it overboard, try this…
I missed a couple of things on the first script, this should work better…
Hi, Greg.
When an ‘else’ section is executed, it means that the previously tested possibilities have been eliminated, so you don’t need to test for them again:
set theTime to (time of (current date)) div hours
if theTime comes before 12 then -- before midday
"Good morning!"
else if theTime comes before 18 then -- midday and after, but before 6 pm
"Good afternoon!"
else -- 6 pm on
"Good evening!"
end if
display dialog the result
Cool NG, I wasn’t aware of that. Thanks for the tip.