Skip to content

Instantly share code, notes, and snippets.

@simonbs
Last active May 22, 2021 21:34
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save simonbs/8dd0735d0cdffb7616b812d849cfc695 to your computer and use it in GitHub Desktop.
Save simonbs/8dd0735d0cdffb7616b812d849cfc695 to your computer and use it in GitHub Desktop.
Greg Jowsiak's "Hi, Speed" widget recreated in Scriptable
// 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)
}
@CarePackageUK
Copy link

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 😂

21DC547B-AD2C-4003-B4B7-5221F786BB4F
4A1AEC29-1E1E-43C2-9D50-E624185ED36D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment