this is a handy little script i wrote up to calculate my pay in an email and list my hours for the week.
-- I am in no way responsible for the use of this script or any financial loss that could be caused by this script. use at your own risk.
on findMinString(num)
set i to 0
if num = 0 then return "00"
repeat until i > 55
if i = num then return i
set i to i + 5
end repeat
end findMinString
on findLeastItem(lst)
tell application "iCal"
set theLeast to start date of item 1 of lst
set theIndex to 1
set iterater to 1
repeat with i in lst
if start date of i ≤ theLeast then
set theLeast to start date of i
set theIndex to iterater
end if
set iterater to iterater + 1
end repeat
return theIndex
end tell
end findLeastItem
on removeItemAtIndex(lst, theIndex)
set newList to {}
set theLength to length of lst
if theLength = 1 then
set newList to {}
else if theLength = theIndex then
set newList to items 1 thru (theLength - 1) of lst
else if theIndex = 1 then
set newList to items 2 thru theLength of lst
else
set newList to items 1 thru (theIndex - 1) of lst & items (theIndex + 1) thru (theLength) of lst
end if
return newList
end removeItemAtIndex
on sortEvents(myList)
set myNewList to {}
repeat until length of myList = 0
set leastIndex to findLeastItem(myList)
set end of myNewList to item leastIndex of myList
set myList to removeItemAtIndex(myList, leastIndex)
end repeat
return myNewList
end sortEvents
on selectCalendar()
tell application "iCal"
set cal_list to get name of every calendar
end tell
set the_choice to choose from list cal_list
if the_choice = false then quit
return item 1 of the_choice
end selectCalendar
on getSecondsOfDays(Ndays)
return ((current date) - (3600 * 24 * Ndays))
end getSecondsOfDays
set res to display dialog "How Many Days back ?" default answer "5"
set days_back to text returned of res
set tt to display dialog "What is your hourly rate" default answer "20"
set theHourlyRate to text returned of tt
set theCalendar to selectCalendar()
tell application "iCal"
set minInHour to 3600
set outputStr to "
"
set totalHours to 0
set today to current date
set weeksHours to every event of calendar theCalendar whose start date is greater than my getSecondsOfDays(days_back)
set weeksHours to my sortEvents(weeksHours)
repeat with evt in weeksHours
set duration to (end date of evt) - (start date of evt)
set sDate to start date of evt as date
set eDate to end date of evt as date
set totalHours to totalHours + duration / minInHour
set sMin to my findMinString(minutes of sDate as number)
set eMin to my findMinString(minutes of eDate as number)
set timeStr to (day of sDate & " " & weekday of sDate & " " & hours of sDate & ":" & sMin & " - " & hours of eDate & ":" & eMin) as string
-- make columns all line up nice
repeat until length of timeStr > 28
set timeStr to timeStr & " "
end repeat
set timeStr to timeStr & " : " & duration / minInHour & " Hours"
set outputStr to outputStr & timeStr & " " & summary of evt & "
"
end repeat
end tell
tell application "Mail"
set outputStr to outputStr & "
total hours = " & totalHours & " : $" & totalHours * theHourlyRate
set str to day of today & "/" & (month of today as number) & "/" & year of today as string
set newMsG to make new outgoing message with properties {subject:"Hours for week ending " & str, content:outputStr, visible:true}
activate
end tell
outputStr