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 / Latest News on MacStories.js
Created August 15, 2020 06:07
Show latest news on MacStories in a widget.
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: red; icon-glyph: newspaper;
let items = await loadItems()
if (config.runsInWidget) {
let widget = createWidget(items)
Script.setWidget(widget)
Script.complete()
} else {
@simonbs
simonbs / Slack Status.js
Last active November 23, 2021 02:37
Peforms OAuth flow against Slack and sets a Slack Status. Meant to be used with Shortcuts.
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: pink; icon-glyph: user;
// In order to use the script, you must create a Slack app and install it on your workspace. Go here to create your app: api.slack.com/apps
// There's two important configurations you must make to the app:
// 1. Add the users.profile:write scope to the app. This scope is necessary to set a Slack status.
// 2. Add the following redirect URL, so Slack will redirect to Scriptable after authorizing.
// https://open.scriptable.app
// Run the script to grant your newly created app authorization to access your Slack account. After you've done this, you can use the script in Shortcuts.
@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 / 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 / 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 Shortcut Links.js
Created September 21, 2019 11:37
Reads a text file containing iCloud links to shortcuts and imports the shortcuts into the Shortcuts app
@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()
@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()