Last active
August 29, 2015 14:05
-
-
Save j05h/cc178c7526a08ea7a54d to your computer and use it in GitHub Desktop.
How many meetings were scheduled on your calendar in the last month?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Determine how much time you spend in meetings over a month | |
*) | |
on sortEvents(theList) | |
-- if there's only one event then it is, by definition, sorted | |
if (count theList) = 1 then return theList | |
-- if we get here we have more than 2 items, so iterate through them | |
set sorted to false -- assume they're out of order | |
repeat until sorted = true | |
set sorted to true | |
repeat with i from 1 to (count theList) - 1 | |
tell application "Microsoft Outlook" | |
-- check two items | |
if start time of item i of theList > start time of item (i + 1) of theList then | |
-- they're out of order, so set the flag | |
set sorted to false | |
-- swap the items (via a temp object | |
copy item (i + 1) of theList to tmpEvent | |
set item (i + 1) of theList to item i of theList | |
set item i of theList to tmpEvent | |
end if | |
end tell | |
end repeat | |
end repeat | |
-- and return the sorted list | |
return theList | |
end sortEvents | |
tell application "Microsoft Outlook" | |
-- get the currently selected message or messages | |
set currentDate to (current date) | |
set oneMonthAgo to currentDate - 31 * days | |
set theEvents to every calendar event whose start time is greater than oneMonthAgo and start time is less than currentDate | |
set theEvents to my sortEvents(theEvents) | |
-- if there are no messages selected, warn the user and then quit | |
if theEvents is {} then | |
display dialog "Please select a meeting first and then run this script." with icon 1 | |
return | |
end if | |
set theSubject to "Hours of Meetings" | |
set theContent to theSubject | |
set curDay to "" | |
set nextDay to "" | |
set startHour to "" | |
set endHour to "" | |
set totalMeetings to 0 | |
set totalHours to 0 | |
set totalDays to 0 | |
set dailyHours to 0 | |
repeat with theEvent in theEvents | |
set totalMeetings to totalMeetings + 1 | |
-- get the information from the message, and store it in variables | |
set startDate to ((start time of theEvent)) | |
set endDate to ((end time of theEvent)) | |
set nextDay to (weekday of startDate) & ", " & (month of startDate) & " " & (day of startDate) | |
if (curDay is not equal to nextDay) then | |
if (dailyHours is not equal to 0) then | |
set theContent to theContent & " " & (dailyHours as integer) & " hours of meetings" | |
end if | |
set theContent to theContent & "<br>" & nextDay & "<br>" | |
set curDay to nextDay | |
set totalHours to totalHours + dailyHours | |
set dailyHours to 0 | |
set totalDays to totalDays + 1 | |
end if | |
set startHour to (time string of startDate) | |
set endHour to (time string of endDate) | |
if (startHour is not equal to endHour) then | |
set used to ((endDate - startDate) / 3600) | |
set dailyHours to dailyHours + used | |
end if | |
end repeat | |
set theContent to theContent & "<br>" | |
set theContent to theContent & "<br>Over " & totalDays & " days:" | |
set theContent to theContent & "<br>Total number of hours of scheduled meetings " & (totalHours as integer) | |
set theContent to theContent & "<br>Total number of scheduled meetings " & totalMeetings | |
set theContent to theContent & "<br>Average hours per meeting " & (totalHours / totalMeetings) | |
set theContent to theContent & "<br>Average hours per day " & (totalHours / totalDays) | |
set newMessage to make new outgoing message with properties {subject:theSubject, content:theContent} | |
open newMessage | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment