Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Use with & to display a random image from a channel onto your phone
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: black; icon-glyph: user-md;
// Based on
// copy and paste into a scriptable widget
// replace the url below with the url if the channel you want to use
// Channel must be public
// uses only images in the channel, does not support text or anything else
const channel = ''
const url = ''+channel.substring(channel.lastIndexOf('/') + 1)+'/contents';
const req = new Request(url)
const res = await req.loadJSON()
const randomBlock = await res.contents[Math.floor(Math.random() * res.contents.length)];
const id =
const i = await new Request(randomBlock.image.square.url);
const img = await i.loadImage();
if (config.runsInWidget) {
// create and show widget
let widget = createWidget(" random image", img)
} else {""+id)
function createWidget(title, img) {
let w = new ListWidget()
w.backgroundColor = new Color("#fff")
w.backgroundImage = img
return w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment