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 / 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 / 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 / Create Gist.js
Last active February 29, 2024 07:53
Scriptable script for creating a gist.
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: brown; icon-glyph: file-code;
// To use this script, you need to configure an OAuth App on GitHub.
// Follow the instructions on the link below to create your OAuth App.
//
// When you are asked to put in a redirect URL, you should put the URL for running this script in Scriptable. Assuming the name of this script is "Create Gist", the URL is scriptable:///run?scriptName=Create%20Gist
//
// https://developer.github.com/apps/building-oauth-apps/creating-an-oauth-app/
//
@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 / Find Nearby Scooter.js
Last active August 17, 2023 17:56
Scriptable script for finding nearby scooterers from the Lime and Bird rental companies.
// You must generate and insert your own API key for Google Maps + Directions JS SDK.
// The script uses Google Maps to display the scooters on a map as well as the route to the nearest scooter. Follow the guide on the link below to obtain an API key.
// https://developers.google.com/maps/documentation/javascript/get-api-key
let googleApiKey = ""
// Choose the enabled rental companies. Set to true to enable the rental company and false to disable it.
let COMPANIES = {
bird: true,
lime: true
}
@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()
@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 / 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 / Append to File.js
Created August 27, 2019 20:31
Appends text to a file. To be used with Shortcuts.
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-blue; icon-glyph: file-signature;
let text = args.shortcutParameter
let fm = FileManager.iCloud()
let filePath = args.fileURLs[0]
let content = fm.readString(filePath)
let newText = content + "\n" + text
fm.writeString(filePath, newText)
Script.complete()