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 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.
My new widget shuffles a random album of the “Top 500 albums of all time” (according to the Rolling Stone magazine) and shows the cover art. Upon tapping on the widget it opens the album either in Spotify or plays it on your Sonos system.
Based on Matt Silverback’s original code, I added AQI calculations and set the widget to present the background color based on the current air quality status.
My new widget shuffles one of your latest Pocket bookmarks and opens the article in Safari once you tap it.
I also built a shortcut which makes it easy to obtain your Pocket access token and stores the whole script at the end. Just save it to your scriptable folder in iCloud Drive.
My next one (Sorry I’m addicted):
I ported my Simpsons Randomizer shortcut to a widget. It shuffles a random episode of The Simpsons. Upon tapping on the widget it plays the episode on Disney+. ¡Ay, caramba!
Okay. I must be dumb. What am I doing wrong? I can’t get a script to show up. I pulled the xkcd example (and others) and this is what I see when I select it from the widget…
The latest Scriptables update made it easier to debug widgets so I fixed a script I had been working on: a way to quickly see what is on the eShop. Tapping will take you to that game on the eShop’s website.
I wish I could make a shelf or a grid of these, but for now this is pretty cool.
I made a widget that shows the most recent article on a Feedbin account. It uses etags for caching and won’t break even when there is no internet connection - it will just show the last item it downloaded and indicate that it’s cached.
Please note as of the latest beta build (155), any script that is calling calling topAlignContent(), centerAlignContent() or bottomAlignContent() on a ListWidget will now throw an error. I’m sorry, but I’ve replaced the functions during the beta with the more flexible addSpacer() function.
If you add a spacer at the top of your widget by calling addSpacer() before adding other elements, your content will be bottom aligned. If you add the spacer at the bottom of your widget, the content will be top aligned. You can also call addSpacer(5) to add a spacer with a fixed height of 5 pixels.
This may happen if the widget crashes for some reason. If you’re using scripts that for others, it’s probably not due to memory constraints. Can you try rebooting your device? Sometimes that helps, at least for a while. It would be interesting to know if that helped.
Would it be possible to create a way to run the widget without actually running the installed version? Debugging is a pain because iOS doesn’t have a way to force refresh a widget.
Also am I missing something or is there no way to find & replace in the script editor?