r/Scriptable • • Nov 03 '21

Solved Help with setting an image as widget background

Not much of a coder and this is referring to the Daily Logs V2 widget (created by u/randomo_redditor). I’m trying to set a background image for the widget without being prompted to select it from my camera roll every time I run it. Is this possible and if so what’s the code I need? Here is the area of the code that I think controls this: https://imgur.com/a/3BwVqsY .

Thanks in advance

P.S (Lines 182-184 is me trying something with no luck, given a ‘Cannot parse response to an image’ error)

3 Upvotes

42 comments sorted by

View all comments

Show parent comment

2

u/[deleted] Nov 04 '21

Finally done it man here ya go:

else if (config.runsInApp && !args.widgetParameter){
    const bcg = new Alert();
    bcg.title = "Change background?";
    bcg.addTextField("Yes or No?");
    await bcg.present();
    if (bcg.textFieldValue(0) == "No") {
    widget.backgroundImage = files.readImage(path)
  } else {
    const img = await Photos.fromLibrary();
    widget.backgroundImage = img;
    files.writeImage(path, img);
  }    

Replace the last else if in the USE_BACKGROUND_IMAGE if statement with this

1

u/dpopov44 Nov 04 '21

Where should I add it?

1

u/[deleted] Nov 04 '21

Here. Just make sure no curly brace gets left out

1

u/dpopov44 Nov 04 '21

Got it, nice work around!

2

u/[deleted] Nov 04 '21 edited Nov 04 '21

My self confidence really was like 📈📉📉📉📈📉📉📈.

2

u/[deleted] Nov 04 '21

Don’t forget to change flair to solved :)

1

u/Spxrkeyy Jul 25 '22

Mind sending the full code, I’m having the same struggle for days now.

1

u/[deleted] Jul 25 '22

I must’ve deleted it, mind sending me yours so I can make the changes? I tried the github link to the code above but it isn’t working

2

u/Spxrkeyy Jul 26 '22

I fixed it myself, i just copied you’re code in the last row, thanks for you’re fast help.

1

u/[deleted] Jul 26 '22

Oh ok perfect.
No worries

1

u/[deleted] Nov 04 '21

Does it work…I did check it multiple times :|