Good scriptable lockscreen widget tutorial and resource?

Welcome! If I understand correctly, you’ve got Scriptable installed but it’s not appearing as an option to add when you customise the Lock Screen? I haven’t seen this myself but I think I remember reading about someone else seeing this and fixing it by restarting their phone so maybe try that first.

Hey, no i wrote the Script myself. I got a hint that i should put this in my Code:
widget.presentAccessoryRectangular()
And then I could choose from the List Scriptable. It would be nice if the docs would say something about it.

A different question. Someone told me that Scriptable refresh randomly itself and runs my code. Is there a good way to prevent this? So it refreshes only once a day? For example in the morgning at 7am.

And what does this do exactly: refreshAfterDate

Oh ok, you wrote “there is no Option to select Scriptable in list” but you meant that you could add a Scriptable widget but not select your script?

As the documentation explains, the ListWidget.present- methods are for previewing how the widget will look when you run the script in the Scriptable app. When loading the widget, be sure to call Script.setWidget(widget).

iOS itself controls widget refresh. refreshAfterDate is explained in the documentation:

let date = new Date(new Date().getTime() + 24*60*60*1000)
date.setHours(7, 0, 0, 0)
widget.refreshAfterDate = date

1 Like

No i really meant i could not select Scriptable in the List.
Only when I added this widget.presentAccessoryRectangular() in my code I saw
the Scriptable app in the list.

So with this code I can control the refresh of the widget? Do I understand this: date.setHours(7, 0, 0, 0) would refresh every 7 hours? What exactly is mean by refreshing the widget. Does it mean my script will rerun?

This is my script: Is there something which can be optimized? Thanks in advance.

const widget = new ListWidget();
//widget.backgroundColor = new Color("#000", 0);
widget.backgroundColor = Color.clear();
widget.spacing = 10

const req = new Request("Some JSON Data");
const res = await req.loadJSON();

const rndNum = getRandomNum(res.data.length);
const todayVerse = res.data[rndNum];

const title = todayVerse.title;
const body = todayVerse.text;


const titleText = widget.addText(title);

titleText.textColor = new Color("#fff", 1);

titleText.centerAlignText();

titleText.font = new Font("AppleSDGothicNeo-Medium", 20);

const bodyText = widget.addText(body);

bodyText.textColor = new Color("#fff", 1)

bodyText.centerAlignText();

bodyText.font = new Font("AppleSDGothicNeo-Regular", 17);

function getRandomNum(max){

return Math.floor(Math.random() * max);

}

widget.presentAccessoryInline();
widget.presentAccessoryCircular();
widget.presentAccessoryRectangular();

if(config.runsInAccessoryWidget){

Script.setWidget(widget);
Script.complete();
}

else {

await widget.presentLarge();

}


Try

let date = new Date(new Date().getTime() + 24*60*60*1000)
date.setHours(7, 0, 0, 0)
console.log(date)

You will see that the next refresh date will be set to 7h am tomorrow: Sun Feb 25 2024 07:00:00 GMT+0100