Created
February 1, 2016 01:32
-
-
Save matthewspear/571fc205abb2af89df55 to your computer and use it in GitHub Desktop.
Calendar name conversion over all events (Manchester CS timetable)
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
tell application "Calendar" | |
tell calendar "Timetable" | |
--reload calendars | |
set theEvents to {} | |
set AllEvents to events | |
repeat with anEvent in AllEvents | |
set {year:y, month:m, weekday:d, time:t} to (start date of anEvent) | |
set dayOfWeek to d as string | |
set afterNoon to (t / 3600 > 12) | |
set i to summary of anEvent | |
if (i = "COMP11212") then | |
set eventName to "Computation" | |
my special_condition(afterNoon, eventName, true, "Examples") | |
else if i = "COMP10120" then | |
set eventName to "First Year Team Project" | |
my special_condition(afterNoon, eventName, false, "Team Project Lab") | |
else if i = "COMP18112" then | |
set eventName to "Distributed Systems" | |
my special_condition(description of anEvent contains "G23", eventName, true, "Labs") | |
my special_condition(description of anEvent contains "LF15", eventName, true, "Examples") | |
else if i = "COMP16212" then | |
set eventName to "Java" | |
my special_condition(afterNoon, eventName, true, "Labs") | |
else if i = "COMP-1st Yr Tutorial" then | |
set eventName to "Tutorial" | |
else if i = "COMP11120" then | |
set eventName to "Mathematical Techniques" | |
my special_condition(afterNoon, eventName, false, "Maths Examples") | |
else if i = "COMP14112" then | |
set eventName to "Artificial Intelligence" | |
my special_condition(afterNoon, eventName, true, "Labs") | |
my special_condition(dayOfWeek is equal to "Thursday", eventName, false, "AI Examples") | |
else | |
set eventName to i | |
end if | |
set summary of anEvent to eventName | |
copy anEvent to end of theEvents | |
end repeat | |
end tell | |
end tell | |
return theEvents | |
-- special_condition() subroutine | |
-- condition: when to change name | |
-- eventName: string appending / changing | |
-- append: append or change (T/F) | |
-- conditionString: string being either appended or changed to | |
on special_condition(condition, eventName, append, conditionString) | |
if condition then | |
if append = true then | |
set eventName to eventName & " " & conditionString | |
else | |
set eventName to conditionString | |
end if | |
end if | |
end special_condition |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment