Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Enthusiast Zone > Classic Macs and Mac OS > applescript

applescript
Thread Tools
yanges
Junior Member
Join Date: Aug 2001
Location: San Fernando Valley
Status: Offline
Reply With Quote
Sep 2, 2001, 02:05 PM
 
hello all

i am using an applescript to greet me when my Cube starts up.....[see below]

what i want is for the greeting to have options so that if it is morning, it will say 'good morning', if evening, it will say 'good evening' etc.....

how do i give it the parameters to check time of day and then utilize the correct script for the time of day?

*****************
--Start script

on run
say "Hello bruce, hope you are well today" using "Ralph"
end run

--end script
******************************

any thoughts on this would be appreciated......

yanges
yanges

please help save our planet!
http://www.therainforestsite.com

Cube 450mhz, 20gb, 832mb ram,OSX.2.6, SoundSticks, 17"Apple Studio Display, iBot
     
acur128
Junior Member
Join Date: May 2001
Status: Offline
Reply With Quote
Sep 2, 2001, 05:51 PM
 
something like this should work:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>set theTime to time string of (current date)
<font color = green>if</font> word <font color = blue>-1</font> of theTime as string is <font color = red>"AM"</font> then
set theGreeting to <font color = red>"Good morning "</font>
set timeofDay to <font color = red>"today"</font>
<font color = green>else</font>
<font color = green>if</font> word <font color = blue>1</font> of theTime as integer &lt; <font color = blue>6</font> then -- is <font color = blue>6</font> o'clock evening?
set theGreeting to <font color = red>"Good afternoon "</font>
set timeofDay to <font color = red>"today"</font>
<font color = green>else</font>
set theGreeting to <font color = red>"Good evening "</font>
set timeofDay to <font color = red>"tonight"</font>
end <font color = green>if</font>
end <font color = green>if</font>
say (theGreeting & <font color = red>"bruce, hope you are well "</font> & timeofDay) as string using <font color = red>"Ralph"</font></font>[/code]
     
yanges  (op)
Junior Member
Join Date: Aug 2001
Location: San Fernando Valley
Status: Offline
Reply With Quote
Sep 2, 2001, 09:36 PM
 
thanks for the script acur128!

i will try it out.......i found some apple script help but could not figure it out......
yanges

please help save our planet!
http://www.therainforestsite.com

Cube 450mhz, 20gb, 832mb ram,OSX.2.6, SoundSticks, 17"Apple Studio Display, iBot
     
blot
Forum Regular
Join Date: Jun 2000
Location: Singapore
Status: Offline
Reply With Quote
Sep 3, 2001, 09:46 AM
 
yanges,

I use this script for my greeting after startup.

tell application "Sound Scripting"
set Cur_Vol to sound volume
set sound volume to 3
quit
end tell
tell application "Finder"
set weekday1 to the weekday of (the current date) as string
set day1 to the day of (the current date) as string
set month1 to the month of (the current date) as string
set the time_slug to my format_time_using(the current date, " ", {"H", "MM"})
if the time of (the current date) is greater than 4.31675E+4 and the time of (the current date) is less than 8.63675E+4 then
set the AMPM_index to "PM"
else
set the AMPM_index to "Ay M"
end if
if the time of (the current date) is greater than 0 and the time of (the current date) is less than 43200 then
set the greeting_phrase to "[[emph -]]Good Morning! "
else if the time of (the current date) is greater than or equal to 43200 and the time of (the current date) is less than 57600 then
set the greeting_phrase to "Good Afternoon! "
else
set the greeting_phrase to "[[emph -]]Good Evening! "
end if
say "[[rate 200]] " & greeting_phrase & "[[rate 240]]Its " & weekday1 & " the " & day1 & "th of " & month1 & ", " & time_slug & " " & AMPM_index without waiting until completion
set volume of Cur_Vol
end tell
tell application "Finder"
activate
end tell

on format_time_using(this_date_record, delimiter_string, format_list)
set the time_index to the time of this_date_record
set the hour_index to ((the time_index) / hours) div 1
set the minute_index to �
(((the time_index) / minutes) - (the hour_index * 60))
set the formatted_time to ""
-- count the number of items in the list
set the item_count to the count of the format_list
-- parse the format list
repeat with i from 1 to the item_count
set this_item to item i of the format_list
if the (hour_index &gt; 12) then
set the hour_index to hour_index - 12
end if
if the (hour_index = 0) then
set the hour_index to 12
end if
set the minute_index to round_truncate(minute_index, 0)
if (the minute_index = 60) then
set the hour_index to hour_index + 1
if the (hour_index &gt; 12) then
set the hour_index to hour_index - 12
end if
set the minute_index to ""
end if
if this_item is "H" then
set the formatted_time to �
the formatted_time & the hour_index as string
else if this_item is "MM" then
set the low_number to 1
set the high_number to 10
if the minute_index is greater than or equal to the low_number and �
the minute_index is less than the high_number then �
set minute_index to �
("O " & (the minute_index as string))
if the minute_index is 0 then
set minute_index to ""
end if
set the formatted_time to �
the formatted_time & minute_index as string
end if
if i is not the item_count then
-- add delimiter
set the formatted_time to �
the formatted_time & delimiter_string as string
end if
end repeat
return the formatted_time
end format_time_using

on round_truncate(minute_index, 0)
set minute_index to (minute_index + 0.5417) div 1
return minute_index
end round_truncate

Anyone care to optimize it for me? It works fine though.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 04:20 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,