Skip to content

Instantly share code, notes, and snippets.

@supermamon
Created December 1, 2020 23:01
Show Gist options
  • Save supermamon/f6d3a59f767e66c8ded3b5ac90417941 to your computer and use it in GitHub Desktop.
Save supermamon/f6d3a59f767e66c8ded3b5ac90417941 to your computer and use it in GitHub Desktop.
PoC of tap targets calling functions
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: blue; icon-glyph: magic;
// PoC: run functions from tap targets
if (args.queryParameters.fn) {
switch (args.queryParameters.fn) {
case 'fn1':
fn1()
break;
case 'fn2':
fn2()
break;
default:
}
return
}
async function fn1(n) {
const a = new Alert()
a.message = `I am function 1`
a.addAction('Ok')
await a.presentAlert()
}
async function fn2(n) {
const a = new Alert()
a.message = `I am function 2`
a.addAction('Ok')
await a.presentAlert()
}
const w = new ListWidget()
const b1 = w.addText('FN1')
b1.centerAlignText()
b1.font = Font.systemFont(20)
b1.url = `scriptable:///run/${encodeURIComponent(Script.name())}?fn=fn1`
w.addSpacer(10)
const b2 = w.addText('FN2')
b2.centerAlignText()
b2.font = Font.systemFont(20)
b2.url = `scriptable:///run/${encodeURIComponent(Script.name())}?fn=fn2`
Script.setWidget(w)
Script.complete()
if (config.runsInApp) await w.presentMedium()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment