Skip to content

Instantly share code, notes, and snippets.

@jansim
Created October 18, 2019 02:31
Show Gist options
  • Save jansim/e9ad4562d5dfd967b1128e07059157b7 to your computer and use it in GitHub Desktop.
Save jansim/e9ad4562d5dfd967b1128e07059157b7 to your computer and use it in GitHub Desktop.
Add reminders to the macOS Reminders.App from the command line
#!/usr/bin/env osascript -l JavaScript
// Add reminders to the macOS Reminders.App from the command line
const RemindersApp = Application('Reminders');
// - Examples -
// Add a new item:
// ./reminder.js add "My cool new reminder"
// Show all available lists:
// ./reminder.js list
// Add item to a specific list (here list #2):
// ./reminder.js add 2 "My cool new reminder in list No. 2"
function run(argv) {
[task, first, second] = argv;
switch (task) {
// Add a new item.
// Either provide online the item as parameter or
// first the list index (see below) and then the item.
// For items with spaces etc. wrap them double quotes like "..."
case 'add':
// If there are two parameters provided let the first one be the list id
var name, listIndex;
if (second) {
listIndex = parseInt(first);
name = second;
} else {
name = first;
}
var list = listIndex ? RemindersApp.lists[listIndex] : RemindersApp.defaultList;
var reminder = RemindersApp.Reminder({name: name});
list.reminders.push(reminder);
break;
// Get a list of all the available reminder lists.
// Each comes with an index number which can be
// used to add items to this specific list.
case 'list':
var lists = RemindersApp.lists
for (let index = 0; index < lists.length; index++) {
const list = lists[index];
console.log(`${index}: ${list.name()}`)
}
break;
default:
console.log("No task specified")
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment