Thanks to everyone in this thread for sharing your scripts! I just wrote my first script by stealing snippets of code from you guysđ
The script fetches a random Trello card from my âOngoingâ list to remind me of the books, games etc. that I havenât finished yet.
let url = 'https://api.trello.com/1/lists/5db1e25fe891bd2449e1de99/cards'
let req = new Request(url)
let json = await req.loadJSON()
let index = Math.floor(Math.random() * json.length)
let randCard = json[index]
let r = new Request('https://api.trello.com/1/cards/' + randCard.id + '/attachments/' + randCard.idAttachmentCover)
let imgJSON = await r.loadJSON()
r = new Request(imgJSON.url)
let img = await r.loadImage()
let widget = createWidget(randCard.name, img)
Script.setWidget(widget)
Script.complete()
function createWidget(title, img) {
let w = new ListWidget()
w.backgroundColor = new Color("#1A1A1A")
let image = w.addImage(img);
image.imageSize = new Size(150,125)
image.cornerRadius = 4
image.centerAlignImage()
let titleTxt = w.addText(title)
titleTxt.applyHeadlineTextStyling()
titleTxt.textColor = Color.white()
titleTxt.textSize = 9
titleTxt.centerAlignText()
w.setPadding(4, 0, 0, 0)
w.url = randCard.url
return w
}
I do have a question though: is it possible to make this script run periodically so that the widget auto-updates? I donât need frequent updates, once a day should do fine. I realized I could create a Shortcuts Automation that runs without confirmation, but are there better methods?