Showing Upcoming Days off Work

This example made me so curious that I had to install iOS 12 Beta 8 on one of my devices just to be able to try Scriptable right now. This App is awesome!

Based on the other scripts I made my own to display future days I have planned to take off from work (which I track in a separate calendar called “Free”):

function handleEvents(events) {
  let table = new UITable();
  for (event of events) {
    let row = new UITableRow();
    row.height = 40;
    row.cellSpacing = 10;
    let columnOptions = [
      {format: {weekday: "long"   }, align: "right",  weight: 100},
      {format: {day:     "2-digit"}, align: "center", weight:  10},
      {format: {month:   "long"   }, align: "left",   weight: 100}
    ];
    for (options of columnOptions) {
      let cell = createCell(event, options);
      row.addCell(cell);
    }
    table.addRow(row);
  }
  QuickLook.present(table);
}

function createCell(event, options) {
  let text = event.startDate.toLocaleDateString("en-US", options["format"]);
  let cell = UITableCell.text(text);
  cell.widthWeight = options["weight"];
  cell[options["align"] + "Aligned"]();
  return cell;
}

function handleError(val) {
  console.error(val);
}

function handleCalendar(calendar) {
  let start = new Date();
  let end   = new Date(2999, 11, 31);
  CalendarEvent.between(start, end, [calendar]).then(handleEvents, handleError);
}  

let calendar = Calendar.forEventsByTitle("Free").then(handleCalendar, handleError);

The result is a table with 3 columns where each row presents 1 day I take off. The (large) left column shows the weekday (right aligned), the (small) middle column shows the day of the month (centered), and the (large) right column shows the month (left aligned).

3 Likes