Last active
May 22, 2021 21:34
-
-
Save simonbs/8dd0735d0cdffb7616b812d849cfc695 to your computer and use it in GitHub Desktop.
Greg Jowsiak's "Hi, Speed" widget recreated in Scriptable
This file contains hidden or 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
// This script recreates Greg Joswiak's widget that counts down to the "Hi, Speed" Apple Event on October 13th, 2020. | |
// You can see Greg's widget in this tweet: | |
// https://twitter.com/gregjoz/status/1313519797879988225 | |
// | |
// You'll need this image for the background: | |
// https://i.imgur.com/t9Jr8kL.png | |
// | |
// I've stored the image at imgs/hispeed.png Scriptable's folder in iCloud Drive. | |
let widget = createWidget() | |
widget.presentMedium() | |
Script.setWidget(widget) | |
Script.complete() | |
function createWidget() { | |
let eventDate = createEventDate() | |
let time = createRelativeTime(eventDate) | |
let bgImg = readBgImage() | |
let widget = new ListWidget() | |
widget.backgroundImage = bgImg | |
widget.addSpacer() | |
let wtitle = widget.addText("Apple Event") | |
wtitle.font = Font.boldSystemFont(20) | |
wtitle.textColor = Color.white() | |
widget.addSpacer(2) | |
let wtime = widget.addText(time) | |
wtime.font = Font.mediumSystemFont(18) | |
wtime.textColor = Color.white() | |
return widget | |
} | |
function createRelativeTime(date) { | |
let now = new Date() | |
let formatter = new RelativeDateTimeFormatter() | |
let str = formatter.string(date, now) | |
return capitalizeFirstLetter(str) | |
} | |
function createEventDate() { | |
let str = "2020-10-13T17:00:00Z" | |
let dateFormatter = new DateFormatter() | |
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" | |
return dateFormatter.date(str) | |
} | |
function readBgImage() { | |
let fm = FileManager.iCloud() | |
let dir = fm.documentsDirectory() | |
let filePath = fm.joinPath(dir, "imgs/hispeed.png") | |
return fm.readImage(filePath) | |
} | |
function capitalizeFirstLetter(str) { | |
return str.charAt(0).toUpperCase() + str.slice(1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey buddy, I copied the text and pasted it but I get this error? Can you help? I kinda new to all this so please go gentle on me 😂