I’m trying to gather a few examples of scripts that work with the new widgets in iOS 14, so people have a place to find inspiration for their own widgets. I would love if you would share your scripts that work with widgets in this thread
Here is my Reddit code, it is not the cleanest, I copied / pasted / trial and error hacked until I got what I wanted. I have set the click to run script which then opens Reddit on that subreddit.
// Shows latest news from MacStories in a table.
// The table shows an image from the article, if available, and the title of the article.
let rReddit = "Scriptable"
let url = "https://www.reddit.com/r/" + rReddit + "/new.json?limit=6"
let req = new Request(url)
let json = await req.loadJSON()
let items = json.data.children
let appURL = "reddit:///r/" + rReddit
if (config.runsInWidget) {
let widget = createWidget(items)
Script.setWidget(widget)
Script.complete()
} else {
//QuickLook.present(createWidget(items));
Safari.open(appURL)
}
function createWidget(items) {
// let item = items[0]
let w = new ListWidget()
w.backgroundColor = new Color("#47761E")
w.centerAlignContent()
let header = w.addText("r/" + rReddit)
header.textColor = Color.black()
header.centerAlignText()
for (item of items) {
var myDate = new Date(item.data.created_utc * 1000)
var myFormDate = addZero(myDate.getHours()) + ":" + addZero(myDate.getMinutes())
let titleTxt = w.addText("• " + myFormDate + " - " + item.data.title)
titleTxt.applyHeadlineTextStyling()
titleTxt.textColor = Color.white()
titleTxt.textSize = 14
}
var nowDate = new Date()
var nowFormDate = addZero(nowDate.getHours()) + ":" + addZero(nowDate.getMinutes())
let footer = w.addText("Last Updated: " + nowFormDate)
footer.textColor = Color.black()
footer.rightAlignText()
return w
}
function addZero(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
I built a widget for informing about a storm nearby. It using some Polish SOAP service (http://burze.dzis.net), but should work for most of Europe (just replace coords). And… you need API key.
I have created super simple scriptable widget which queries api for Brainkeeper app (personal assistant for foreign vocabulary) to get random word from my list of words I collected. Super cool to have always foreign words in my sight to remember words better.
Thanks for this Scriptable!
Several of the other widgets in this thread have a gradient background. Try taking a look at those to see how they do it. You’ll want to keep an eye out for mentions of LinearGradient and widget.backgroundGradient.