Skip to content

Instantly share code, notes, and snippets.

@PtruckStar
Last active May 7, 2024 02:28
Show Gist options
  • Save PtruckStar/e80b8d89197775ff2fff6fd3b452aaab to your computer and use it in GitHub Desktop.
Save PtruckStar/e80b8d89197775ff2fff6fd3b452aaab to your computer and use it in GitHub Desktop.
sticky notes widget with scriptable
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-green; icon-glyph: sticky-note;
/*
#################################
####simple sticky note widget####
#################################
please read below for usage!!
you must configure font size and
background-color first before
typing your notes and separating
it by "." from your note
CONFIG:
---background color---
green, red, yellow, blue, dynamic, #hex
---text size---
small, medium, large
---pointed note---
if you want to add more than one poin
use ", " to sparate each poin
SEPARATE YOUR NOTE AND CONFIG BY "."
USAGE: (config).(note)
e.g : medium green. note1, note2, ...
or just note: note1, note2, ...
made by @morinagapltynm
################################# */
let placeholder = "Please type your note on the widget parameter"
let input = (args.widgetParameter == null) ? placeholder : args.widgetParameter
let define = input.split(/\.\s(.*)|\.(.*)/)
let conf = define[0]
let noteColor = Color.black()
// fontSize
if (conf.match(/small/i)){
fontSize = 16
}else if (conf.match(/medium/i)){
fontSize = 32
}else if (conf.match(/large/i)){
fontSize = 45
}else{
//default
fontSize = 16
}
// bgColor default is random
color = {
"green": "C5EA9C",
"yellow": "FFFFA1",
"blue": "B1DAE4",
"red": "FFC2E4",
"white": "F6F6F7",
"black": "191919"
}
if (conf.match(/green/i)){
bgColor = new Color(color.green)
}else if (conf.match(/yellow/i)){
bgColor = new Color(color.yellow)
}else if (conf.match(/blue/i)){
bgColor = new Color(color.blue)
}else if (conf.match(/red/i)){
bgColor = new Color(color.red)
}else if (conf.match(/#/)){
//custom color
let prefix = conf.indexOf("#")
let ctmClr = conf.slice(prefix + 1, prefix + 7)
bgColor = new Color(ctmClr)
}else if (conf.match(/dynamic/i)){
bgColor = Color.dynamic(new Color(color.white), new Color(color.black))
noteColor = Color.dynamic(new Color(color.black), new Color(color.white))
}else{
//random as default
let hex = Object.values(color)
bgColor = new Color(hex[Math.floor(Math.random() * 4)])
}
// note
if (define.length == 1){
note = define[0].replace(/, |,/g, "\n• ")
}else{
note = define[1].replace(/, |,/g, "\n• ")
}
// draw widget
let w = new ListWidget()
w.refreshAfterDate = new Date(Date.now()+1000*60*60*24*30*12)
let text = (note.match("\n") === null) ? w.addText(note) : w.addText("• " + note)
text.font = Font.mediumMonospacedSystemFont(fontSize)
text.textColor = noteColor
w.backgroundColor = bgColor
// run widget
if(!config.runsInWidget){
w.presentMedium()
}
Script.setWidget(w)
Script.complete()
@PtruckStar
Copy link
Author

PtruckStar commented Nov 3, 2020

simple sticky note widget

6200D611-A51F-4AC9-9E4A-C010BA347440

Type the configuration and note in widget parameter

config:

  • background color

green, red, yellow, blue, dynamic, or #hex

  • text size

small, medium, large

sparate config and note by: "."

text note:

  • add more than one poin

use ", " to sparate each poin

usage:

(config).(note)

e.g :

medium green. noteone, notetwo, ...

large, #ff0000. singlenotenopoint

or just note: *w/random background color

noteone, notetwo, notemore ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment