Bahá'í Library Online
. . . .
.
>>   Software
> add tags
Abstract:
Microsoft Entourage apple script to remind one to say the obligatory prayer before sunset. Script retrieves the sunset time from the internet for your local area and uses that as a basis for the reminder.

Obligatory Prayer Reminder Script:
Applescript code for Entourage 2004 (Macintosh only)

by Brett Zamir

As forgetful as I am, I found it an interesting excercise to adapt an existing script (I can't remember where I got it from--if you are the author of the script I have adapted, please let me know) for the Apple computer (Macintosh) to insert a task into Microsoft Entourage 2004 every day to remind one to say the (short) obligatory prayer before sunset. The uniqueness of this script is that it actually retrieves the sunset time from the internet for your local area and uses that as a base for the reminder (e.g., you can set it to notify you 2 hours before the sunset for that day).

To adapt this script for your circumstances, you will need to do the following:
  1. Change the line that says "set theChoice to "Illinois"" to reflect your state--or if you for some reason want the script to ask you for your state each time, you can change the line to have "--" at the beginning of the line and remove those hyphens from the line that begins "set theChoice to choose from list..."
  2. For the lines that say: "set theButton to "Northbrook"" and "set theName to "Northbrook"", change them to reflect your city's name (or, if you want to get asked each time, remove the double hyphens from the two lines above these).
  3. For the line that says "set hhh to 5", change the number to reflect the number of hours before sunset you want to be reminded. (You could adapt the script to ask you each time--let me know if you would like help doing this.)
  4. You also need to save the copied file in Script Editor or the like (as a script (.scpt) file, not an application) and place it in the "Entourage Script Menu Items" folder under Documents->Microsoft User Data). You can then invoke it from the script menu in Entourage 2004. Or, if you want this script to run every morning, you can get some kind of script automator (so that you don't have to fill up your tasks ahead of time or, on the other hand, to remember to invoke the script each day).

You could adapt the script to add the reminder task to other programs intead of Entourage 2004 (if the program is scriptable).

Perhaps this can all be done more simply with Apple's System 10.4 "Automator" feature now, but I wanted to offer the idea at least. The idea could be adapted to provide any optional or required combination of the following: reminders in advance of two hours before sunset (the latest time for "dawn prayers"), before sunrise (for a reminder for the fast if you are a real early bird), before noon (real "noon" is different than 12pm)--of after noon if you want to be sure the script is not reminding you too early to say it, before 2 hours after sunset (per the medium obligatory prayer), etc..
-- two lists that enable someone to choose a state from a list and then look up the appropriate code for that state
set fullStateName to {"Alabama", "Alaska", "American Samoa", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware",
 "D.C.", "Florida", "Georgia", "Guam", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", 
"Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", 
"New Mexico", "New York", "North Carolina", "North Dakota", "N. Mariana Islands", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Puerto
 Rico", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virgin Islands", "Virginia", "Washington",
 "West Virginia", "Wisconsin", "Wyoming"}
set stateAbbreviation to {
"AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", 
"MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PA", "PR", "RI", "SC", "SD", "TN", 
"TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY"}

-- let the user pick the state

--set theChoice to choose from list fullStateName with prompt "Choose the state" default items {"New Mexico"} OK button name "Choose State" 
cancel button name "Quit" without multiple selections allowed and empty selection allowed

set theChoice to "Illinois"


-- check to see if they picked something
if the theChoice is false then
	-- if no choice was made then quit
	return 0
else
	-- look up the appropriate state code
	set the theState to item (listPosition((theChoice as string), fullStateName)) of the stateAbbreviation
end if

-- let the user enter a location
--set theReply to display dialog "Enter in the name of the city." default answer "Santa Fe" buttons {"Quit", "Enter Place"} default button
 "Enter Place"
--set {theButton, theName} to {button returned, text returned} of the theReply

set theButton to "Northbrook"
set theName to "Northbrook"

-- check to see if a proper location was entered, must be 1 to 32 characters
if (theButton is "Quit") then
	set theState to ""
	return 0
else
	if (theName is "") then
		display dialog "No name was entered."
		return 0
	else
		if ((length of theName) is greater than 32) then
			display dialog "The name must be less than 32 characters long."
			return 0
		else
			-- url encode the name so that it can be passed to the server correctly
			set thePlace to encodeText(theName, true, true)
		end if
	end if
end if

-- set up the date components to send to the server

--original date info
set theDate to current date
set theYear to year of theDate
set theMonth to month of theDate as integer
set theDay to day of theDate as integer


(*set theReply to display dialog "Enter a year:" default answer (year of (current date) as integer)
set theReply2 to display dialog "Enter a month:" default answer (month of (current date) as integer)
set theReply3 to display dialog "Enter a starting day:" default answer (day of (current date) as integer)


set theYear to {text returned} of theReply as integer
set theMonth to {text returned} of theReply2 as integer
set theDay to {text returned} of theReply3 as integer
*)

-- set up shell command which uses the shell tool "curl"
-- to post the form and dowload the web page


set theCommand to "curl -d 'FFX=1&ID=APPLSCPT&xxy=" & theYear & "&xxm=" & theMonth & "&xxd=" & theDay & "&st=" & theState & 
"&place=" & thePlace & "&ZZZ=END' http://aa.usno.navy.mil/cgi-bin/aa_pap.pl"

-- execute the shell command and save the resulting web page to a variable
set theWebPage to do shell script theCommand

-- parse the downloaded web page
set numberMatched to 0
try
	-- separate the web page into lines
	repeat with theLine in (paragraphs of theWebPage)
		-- look for the lines that contain Sunrise and Sunset
		-- coerce those lines into date objects and save them in appropriate variables
		if theLine contains "Sunrise" then
			set sunriseTime to date theLine
			set numberMatched to numberMatched + 1
		end if
		
		if theLine contains "Sunset" then
			set sunsetTime to date theLine
			set numberMatched to numberMatched + 1
		end if
	end repeat
end try

-- check to see if we found both Sunrise and Sunset
if numberMatched is less than 2 then
	-- if we didn't find them then something went wrong
	display dialog "Error in retrieving the data."
else
	-- if we found both then put up a dialog with the times
	set uuu to time string of sunsetTime
	
	display dialog return & (((theMonth as string) & "/" & theDay as string) & "/" & theYear as string) & ": " & "Rise: " 
& time string of sunriseTime & "; " & "Set: " & uuu & return
end if


-- The Apple example subroutines follow:

-- this sub-routine is used to find the position of an item in a list
on listPosition(thisItem, thisList)
	repeat with i from 1 to the count of thisList
		if item i of thisList is thisItem then return i
	end repeat
	return 0
end listPosition

-- this sub-routine is used to encode a character 
on encodeChar(thisChar)
	set the ASCIINum to (the ASCII number thisChar)
	set the hexList to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
	set x to item ((ASCIINum div 16) + 1) of the hexList
	set y to item ((ASCIINum mod 16) + 1) of the hexList
	return ("%" & x & y) as string
end encodeChar

-- this sub-routine is used to encode text
on encodeText(thisText, encodeURLA, encodeURLB)
	set the standardCharacters to "abcdefghijklmnopqrstuvwxyz0123456789"
	set the URLAChars to "$+!'/?;&@=#%><{}[]"~`^\|*"
	set the URLBChars to ".-:"
	set the acceptableCharacters to the standardCharacters
	if encodeURLA is false then set the acceptableCharacters to the acceptableCharacters & the URLAChars
	if encodeURLB is false then set the acceptableCharacters to the acceptableCharacters & the URLBChars
	set the encodedText to ""
	repeat with thisChar in thisText
		if thisChar is in the acceptableCharacters then
			set the encodedText to (the encodedText & thisChar)
		else
			-- needed to make an exception for spaces, they have to be converted
			-- into plus signs in order for the place names to work properly
			if thisChar is in {" "} then
				set the encodedText to (the encodedText & "+") as string
			else
				set the encodedText to (the encodedText & encodeChar(thisChar)) as string
			end if
		end if
	end repeat
	return the encodedText
end encodeText


tell application "Microsoft Entourage"
	activate
	
	(*set myTasks to selection
	repeat with theTask in myTasks
		get (due date) of theTask
	end repeat
	*)
	
	set ppp to (current date)
	set timeString to time string of ppp
	
	(*	if sunsetTime > ppp then set qqq to sunsetTime
	if sunsetTime ? ppp then set qqq to sunsetTime of ((day of (current date)) + 1)
*)
	set hhh to 5 --number of hours/minutes before sunset (make into a variable later)
	set qqq to sunsetTime - (60 * 60 * hhh)
	set qqq to (date string of (current date) as string) & " " & time string of qqq
	make new task with properties {name:"Obligatory Prayer reminder", remind date and time:date (qqq)}
	
	
	--format for such conversions/comparisons: if (current date) is greater than date ("11:00 PM" & "") then
	
end tell

--set this script to run every morning (so that Entourage tasks need not be clogged up with a string of advance sunset reminder tasks)
Back to:   Software
Home Site Map Forum Links Copyright About Contact
.
. .