Skip to content

Instantly share code, notes, and snippets.

Last active March 28, 2023 10:28
What would you like to do?
A Scriptable widget which shuffles a random Simpsons episode and plays it on Disney+ upon interaction
let openWith = args.widgetParameter
let widget = new ListWidget()
widget.setPadding(8, 10, 5, 10)
widget.backgroundColor = new Color("#111E6C")
await loadImage()
await getRandomEpisode()
async function getRandomEpisode() {
// load json from iCloud Drive
let fm = FileManager.iCloud()
let dir = fm.documentsDirectory()
let path = fm.joinPath(dir, "simpsons.json")
let contents = Data.fromFile(path)
let episodes = JSON.parse(contents.toRawString())
var episodeList = [];
for(var i in episodes)
let randomNumber = getRandomNumber(1, episodeList.length)
let chosenItem = episodeList[randomNumber-1]
let title = chosenItem.title
let season = chosenItem.seasonNumber
let episode = chosenItem.episodeNumber
widget.url = chosenItem.url
let titleText = widget.addText(title)
titleText.textColor = Color.white()
titleText.font = new Font("AvenirNext-DemiBold", 13)
titleText.lineLimit = 2
await loadMetadata(season, episode)
async function loadMetadata(season, episode) {
let tvMazeUrl = "" + season + "&number=" + episode
let tvMazeRequest = new Request(tvMazeUrl)
let tvMazeResponse = await tvMazeRequest.loadJSON()
let excerptText = widget.addText(tvMazeResponse.summary.replace(/<\/?[^>]+(>|$)/g, ""))
excerptText.textColor = Color.lightGray()
excerptText.font = new Font("AvenirNext-Medium", 13)
excerptText.lineLimit = 4
let airDate = new Date(Date.parse(tvMazeResponse.airstamp))
let df = new DateFormatter()
let strDate = df.string(airDate)
let seasonEpiside = "S" + add_zero(season, 2) + "E" + add_zero(episode, 2)
let dateAddedText = widget.addText("📺 " + seasonEpiside+" 📅 " + strDate)
dateAddedText.textColor = Color.white()
dateAddedText.font = new Font("AvenirNext-DemiBold", 11)
// helper function to download an image
async function loadImage() {
let req = new Request("")
let image = await req.loadImage()
let widgetImage = widget.addImage(image)
widgetImage.imageSize = new Size(65,25)
// random number, min and max included
function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
// add leading zeros to a number
function add_zero(number, length) {
var num = '' + number;
while (num.length < length) {
num = '0' + num;
return num;
Copy link

marco79cgn commented Aug 29, 2020


iOS 14 Custom Widget made with the help of the Scriptable app.
It shuffles a random episode of The Simpsons. Upon tapping on the widget it plays the episode on Disney+.


  • iOS 14 Developer Beta 5 (or above)
  • Scriptable TestFlight version 1.5 (156)
    Join the beta here
  • A Disney+ subscription
  • The json file containing all episodes
    Please download it and put it in your iCloud Drive Scriptable folder with the file name "simpsons.json"
  • Optional:
    I built a shortcut which automates the whole process. It downloads both the episodes metadata file (simpsons.json) and the widget script above. Just choose your Scriptable folder in iCloud Drive twice as destination. After that you'll find the script in your Scriptable app (named simpsonsRandomizer).


A big Thank you to @simonbs for making great apps like Scriptable, DataJar or Jayson.

Copy link

Thanks for sharing. This widget has given me some inspiration!

Copy link

kann ich die Beschreibung der Episode auch auf deutsch einstellen?
Und in welchem Intervall werden neue Episoden in dem Widget angezeigt?

Vielen Dank!

Copy link

Zudem bekomme ich auf meinem iPad mini 4 mit iOS 14 eine Fehlermeldung, sofern ich das entsprechende Widget erstellen möchte:
Error on line 19:37: TypeError: null is not an object (evaluating 'contents.toRawString')

Wie kann ich den Fehler beheben? Auf meinem iPhone läuft das Widget wunderbar!

Um Hilfe bin ich sehr dankbar!

Copy link

How did you make the json? What method to pull all that data? I want to make a similar widget but for Rick and Morty.

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