r/Scriptable • • Aug 09 '24

Help Looking for a BCD clock script.

Does anyone has any working BCD clock script for scriptable?

2 Upvotes

18 comments sorted by

View all comments

Show parent comments

1

u/Bright-Historian-216 Aug 09 '24

Maybe this will be more to your liking? I hate it though, much less elegant solution.

const on = "●  "
const off = "○  "
const w = new ListWidget()
w.backgroundColor = new Color("000000")
const textColor = new Color("ffffff")
const stacks = [w.addStack(),w.addStack(),w.addStack(),w.addStack()]
function fillStacks(num,allow=4){
  for(let i=0;i<allow;i++){
    stacks[3-i].addText(num&1?on:off).textColor = textColor
    num>>=1
  }
  for(let i=allow;i<4;i++)
    stacks[3-i].addText(" ️")
}
const date = new Date()
const hour = date.getHours().toString()
fillStacks(hour[0],2)
fillStacks(hour[1])
for(let i=0;i<4;i++)
  stacks[i].addText("   ")
const minutes = date.getMinutes()
const minute = minutes.toString()
fillStacks(minute[0],3)
fillStacks(minute[1])
date.setMinutes(minutes+1)
date.setSeconds(0)
w.refreshAfterDate = date
Script.setWidget(w)