Skip to content

Instantly share code, notes, and snippets.

@alexito4
Last active May 8, 2019 14:35
Show Gist options
  • Save alexito4/f921aebdadb90b78b44831ef103ab370 to your computer and use it in GitHub Desktop.
Save alexito4/f921aebdadb90b78b44831ef103ab370 to your computer and use it in GitHub Desktop.
Swift script to convert Reminders export files (.ics) to lists.
#!/usr/bin/swift sh
import Foundation
guard let path = CommandLine.arguments.dropFirst().first else { exit(1) }
print(path)
let content = try! String(contentsOfFile: path)
let lines = content
.split(separator: "\r\n")
let summaryPrefix = "SUMMARY:"
let extraPrefix = "X-APPLE-ACTIVITY;VALUE="
var items = [String]()
for line in lines {
if line.starts(with: summaryPrefix) {
items.append(String(line.dropFirst(summaryPrefix.count)))
}
if line.starts(with: extraPrefix) {
items[items.count-1].append(" \(line.dropFirst(extraPrefix.count))")
}
}
print("Found \(items.count) items.")
print(items.joined(separator: "\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment