Skip to content

Instantly share code, notes, and snippets.

View simonbs's full-sized avatar
🐼

Simon B. Støvring simonbs

🐼
View GitHub Profile
@simonbs
simonbs / Cycling Classifications.js
Created March 10, 2019 08:50
Scriptable Script: Cycling Classifications
let url = "https://sports-data.api.tv2.dk/sports-data-backend/cycling/stages/1720933/standings"
let req = new Request(url)
req.headers = { "Accept": "application/json" }
let json = await req.loadJSON()
let rawStandings = json["cyclingGeneralStandings"]
let standings = rawStandings.map(mapStanding)
let table = formatStandings(standings)
QuickLook.present(table)
if (config.runsWithSiri) {
let tts = siriText(standings)
@simonbs
simonbs / On TV Now.js
Last active May 28, 2019 12:00
Scriptable script that shows what's on Danish television right now.
let date = new Date()
let y = ""+date.getFullYear()
let m = ""+(date.getMonth() + 1)
let d = ""+date.getDate()
let dateStr = y+"-"+zeroPrefix(m)+"-"+zeroPrefix(d)
let siriArgs = args.siriShortcutArguments
let channelId = siriArgs.channel
let channelIds = []
if (channelId != null) {
channelIds = [channelId]
@simonbs
simonbs / On TV Tonight.js
Last active May 28, 2019 12:00
Scriptable script that shows what's on Danish television tonight.
let windowStart = new Date()
let windowEnd = new Date()
windowStart.setHours(19)
windowStart.setMinutes(00)
windowStart.setSeconds(00)
windowEnd.setHours(21)
windowEnd.setMinutes(30)
windowEnd.setSeconds(00)
let channelIds = [
"1", // DR1
@simonbs
simonbs / Import Contacts from Slack.js
Created October 26, 2018 22:56
Scriptable script that imports contacts from Slack. Existing contacts will also have their avatar and social profiles updated. The contacts must have their phone number set in Slack.
// In order to use the script,
// you must create a Slack bot
// with the user:read scope and
// generate an accesss token.
// The script will prompt you
// to copy the access token in.
// The token is stored securely
// in the keychain.
let containers = await ContactsContainer.all()
let contacts = await Contact.all(containers)
@simonbs
simonbs / XKCD.js
Created September 29, 2019 19:03
Scriptable script that shows today's XKCD in Siri.
let url = "https://xkcd.com/info.0.json"
let req = new Request(url)
let json = await req.loadJSON()
let imgURL = json["img"]
alt = json["alt"]
req = new Request(imgURL)
let img = await req.loadImage()
QuickLook.present(img)
if (config.runsWithSiri) {
Speech.speak(alt)
@simonbs
simonbs / Import Contacts From Slack.js
Last active September 29, 2019 19:14
Scriptable script to import contacts from Slack.
// In order to use the script, you must create a Slack bot with the user:read scope and generate an accesss token.
// The script will prompt you to copy the access token in.
// The token is stored securely in the keychain.
let containers = await ContactsContainer.all()
let contacts = await Contact.all(containers)
let slackUsers = await loadSlackUsers()
slackUsers = slackUsers.filter(u => {
return !u["is_bot"]
&& !u["deleted"]
&& !u["is_restricted"]
@simonbs
simonbs / Snow Stats.js
Created January 2, 2020 11:02
Reads slope data from skeikampen.no
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: blue; icon-glyph: snowflake;
let html = await loadHTML()
let stickyItems = getStickyItems(html)
let liftCounts = getLiftCounts(stickyItems[1])
let slopeCounts = getSlopeCounts(stickyItems[2])
let snowDepth = getSnowDepth(stickyItems[3])
let windSpeed = getWindSpeed(stickyItems[4])
let tableTexts = [
@simonbs
simonbs / List Tags.js
Last active April 18, 2020 10:52
Lists unique tags across multiple files. To be used with Shortcuts.
let fm = FileManager.iCloud()
let filePaths = args.fileURLs
let tags = filePaths.reduce((cur, e) => {
return cur.concat(fm.allTags(e))
}, [])
let uniqueTags = tags.filter((t, idx) => {
return tags.indexOf(t) === idx
})
let output = {"tags": uniqueTags}
Script.setShortcutOutput(output)
@simonbs
simonbs / Remove Tag.js
Last active April 18, 2020 10:52
Removes a tag from a file. To be used with Shortcuts.
let tag = args.shortcutParameter
let fm = FileManager.iCloud()
let filePath = args.fileURLs[0]
fm.removeTag(filePath, tag)
let tags = fm.allTags(filePath)
let output = {"tags": tags}
Script.setShortcutOutput(output)
Script.complete()
@simonbs
simonbs / Add Tag.js
Last active April 18, 2020 10:52
Adds a tag to a file. To be used with Shortcuts.
let tag = args.shortcutParameter
let fm = FileManager.iCloud()
let filePath = args.fileURLs[0]
fm.addTag(filePath, tag)
let tags = fm.allTags(filePath)
let output = {"tags": tags}
Script.setShortcutOutput(output)
Script.complete()