MacNN Forums (http://forums.macnn.com/)
-   Classic Macs and Mac OS (http://forums.macnn.com/classic-macs-and-mac-os/)
-   -   applescript (http://forums.macnn.com/64/classic-macs-and-mac-os/44275/applescript/)

 
yanges Sep 2, 2001 03:05 PM
applescript
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 :rolleyes:
 
acur128 Sep 2, 2001 06: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 Sep 2, 2001 10:36 PM
thanks for the script acur128!

i will try it out.......i found some apple script help but could not figure it out...... :D
 
blot Sep 3, 2001 10:46 AM
yanges,

I use this script for my greeting after startup. :D

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.
 
All times are GMT -4. The time now is 06:20 AM.

Copyright © 2005-2007 MacNN. All rights reserved.
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2016, vBulletin Solutions, Inc.


Content Relevant URLs by vBSEO 3.3.2