Skip to content

Instantly share code, notes, and snippets.

@sunsetsonwheels
Last active October 3, 2021 15:58
Show Gist options
  • Save sunsetsonwheels/3a6c60c78886cb741f287cecf7a6b647 to your computer and use it in GitHub Desktop.
Save sunsetsonwheels/3a6c60c78886cb741f287cecf7a6b647 to your computer and use it in GitHub Desktop.
Scriptable water intake widget
const iCloudData = importModule("Scriptable iCloud Data");
const logFileName = "water.json";
let waterData = args.shortcutParameter;
if (waterData) {
iCloudData.writeJSONFile(logFileName, waterData);
} else {
if (iCloudData.doesFileExist(logFileName)) {
waterData = iCloudData.readJSONFile(logFileName);
}
}
const widget = new ListWidget();
widget.backgroundColor = new Color("#0e87cc");
const consumedText = widget.addText(`${waterData ? waterData.water : "?"} 💧`);
consumedText.font = Font.mediumSystemFont(22);
const goalText = widget.addText("2000");
goalText.font = Font.boldSystemFont(34);
let consumedDate;
if (waterData) {
consumedDate = widget.addDate(new Date(waterData.date));
consumedDate.applyRelativeStyle();
} else {
consumedDate = widget.addText("????/??/??");
}
consumedDate.font = Font.lightSystemFont(14);
if (config.runsInWidget) {
Script.setWidget(widget);
} else if (config.runsInApp) {
await widget.presentSmall();
}
Script.complete();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment