Last active
October 30, 2024 10:52
-
-
Save rnorth/040d0395036d8066740da321e830d666 to your computer and use it in GitHub Desktop.
agenda: exports today's calendar entries from Mac Calendar.app into a markdown file to enable note-taking
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
#!/usr/bin/swift | |
// | |
// agenda: exports today's calendar entries from Mac Calendar.app into a markdown file to enable note-taking | |
// | |
// Example usage: | |
// agenda > agenda-$(date +%Y-%m-%d).md | |
// | |
import EventKit | |
let semaphore = DispatchSemaphore(value: 1) | |
defer { | |
semaphore.wait() | |
} | |
let store = EKEventStore() | |
var timeFormatter = DateFormatter() | |
timeFormatter.dateFormat = "HH:mm" | |
var dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = "yyyy-MM-dd E" | |
store.requestAccess(to: .event, completion: { (success, error) -> Void in | |
var calendar = Calendar.current | |
calendar.timeZone = NSTimeZone.local | |
let dateAtMidnight = calendar.startOfDay(for: Date()) | |
var components = DateComponents() | |
components.day = 1 | |
components.second = -1 | |
let endDate = calendar.date(byAdding: components, to: dateAtMidnight) | |
let predicate = store.predicateForEvents(withStart: dateAtMidnight, end: endDate!, calendars: nil) | |
let events = store.events(matching: predicate) | |
let todayDate = dateFormatter.string(from: Date()) | |
print("# \(todayDate)") | |
print("") | |
for event in events { | |
if (event.status == EKEventStatus.canceled) { | |
continue | |
} | |
let date = dateFormatter.string(from: event.startDate) | |
let start = timeFormatter.string(from: event.startDate) | |
let end = timeFormatter.string(from: event.endDate) | |
let title = event.title!.replacingOccurrences(of: "FW: ", with: "") | |
//let location = event.location! | |
let id = event.eventIdentifier! | |
print("------") | |
print("---") | |
print("event: \(title)") | |
print("date: \(date)") | |
print("time: \(start) - \(end)") | |
//print("location: \(location)") | |
print("id: \(id)") | |
print("---") | |
print("") | |
print("## \(title)") | |
print("") | |
print("") | |
print("") | |
print("") | |
} | |
semaphore.signal() | |
}) | |
semaphore.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment