r/Scriptable • • Aug 22 '20

Script IP Address Widget

This will get your external IP Address and display it on your home screen

// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: blue; icon-glyph: magic;
let widget = await createWidget();
Script.setWidget(widget);

async function createWidget() {
  const req = new Request("http://ipinfo.io/json");
  const data = await req.loadJSON();
  let IPHeader = "Current IP Address:"
  let IP = data.ip
  let w = new ListWidget()
  w.backgroundColor = new Color(color2())
  let titleTxt = w.addText(IPHeader)
  titleTxt.applyHeadlineTextStyling()
  titleTxt.textColor = new Color(color1())
  let bodyTxt = w.addText(IP)
  bodyTxt.applyBodyTextStyling()
  bodyTxt.textColor = new Color(color1())
  return w
}

function color1() {
  let mode = Device.isUsingDarkAppearance()
  if (mode == "true") {
    return "#f2f2f2";
  }
  else {
    return "#191919";
  }
}

function color2() {
  let mode = Device.isUsingDarkAppearance()
  if (mode == "true") {
    return "#191919";
  }
  else {
    return "#f2f2f2";
  }
}

17 Upvotes

8 comments sorted by

View all comments

1

u/Ronghaha Dec 20 '20

I can't run this script in scriptable, but I really need it.

It's showed error.

2020-12-20 18:39:07: Error on line 15:36: TypeError: titleTxt.applyHeadlineTextStyling is not a function. (In 'titleTxt.applyHeadlineTextStyling()', 'titleTxt.applyHeadlineTextStyling' is undefined)

1

u/Ronghaha Dec 21 '20

Ok, mute the two function with //, then it can work.

2

u/picachu11 Dec 28 '20

I have the same error. Can you post a valid script please?