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 / Animals of the Day.js
Created November 1, 2020 13:05
Shows an image of an animal
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: purple; icon-glyph: paw;
let pandaURL = "https://c402277.ssl.cf1.rackcdn.com/photos/7749/images/story_full_width/HI_204718.jpg?1414503137"
let slothURL = "https://c402277.ssl.cf1.rackcdn.com/photos/6518/images/story_full_width/iStock_000011145477Large_mini_%281%29.jpg?1394632882"
let redPandaURL = "https://c402277.ssl.cf1.rackcdn.com/photos/8036/images/story_full_width/WEB_279173.jpg?1418412345"
let pandaImg = await getImage(pandaURL)
let slothImg = await getImage(slothURL)
let redPandaImg = await getImage(redPandaURL)
@simonbs
simonbs / Indie App Santa.js
Last active December 2, 2020 20:46
Indie App Santa
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: red; icon-glyph: calendar-alt;
let data = await loadData()
let app = data.today[0]
let widget = null
if (config.runsInWidget) {
if (config.widgetFamily == "small") {
widget = await createSmallWidget(app)
} else {
@simonbs
simonbs / Hi, Speed.js
Last active May 22, 2021 21:34
Greg Jowsiak's "Hi, Speed" widget recreated in Scriptable
// This script recreates Greg Joswiak's widget that counts down to the "Hi, Speed" Apple Event on October 13th, 2020.
// You can see Greg's widget in this tweet:
// https://twitter.com/gregjoz/status/1313519797879988225
//
// You'll need this image for the background:
// https://i.imgur.com/t9Jr8kL.png
//
// I've stored the image at imgs/hispeed.png Scriptable's folder in iCloud Drive.
let widget = createWidget()
@simonbs
simonbs / Tour de France Profile.js
Created July 13, 2021 14:37
Scriptable script showing a profile of the current Tour de France stage
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: yellow; icon-glyph: bicycle;
let stages = await loadStages()
let stage = findStage(stages)
if (stage == null) {
let widget = createTournamentOverWidget()
await widget.presentMedium()
} else {
let stageDetails = await loadStageDetails(stage.id)
@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 / KeyboardAvoidingView.swift
Created January 24, 2022 21:29
Avoid undocked keyboard at bottom.
// Sample code made in response to this tweet:
// https://twitter.com/stroughtonsmith/status/1485719749673820163
final class MainView: UIView {
private let textView: UITextView = {
let this = UITextView()
this.translatesAutoresizingMaskIntoConstraints = false
this.text = "I'm a text view"
this.font = .preferredFont(forTextStyle: .body)
this.textColor = .label
@simonbs
simonbs / Example.swift
Created April 5, 2022 19:14
Present a portrait-only UIViewController wrapped in UIViewControllerRepresentable from a SwiftUI view.
/**
* This file shows how we can tie all of the above together.
*/
import SwiftUI
// This view can have any orientation-
struct SettingsView: View {
@State private var isPortraitOnlyViewPresented = false
@simonbs
simonbs / Is Slack down?.js
Created September 3, 2020 04:56
Scriptable script to check if Slack is down. Works with Siri and widgets.
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: orange; icon-glyph: exclamation-triangle;
// Checks if Slack is down by examining their status page. Works perfectly with Siri.
let url = "https://status.slack.com"
let r = new Request(url)
if (config.runsWithSiri) {
let isDown = await getIsDown(url)
if (isDown) {
Speech.speak("Yes")
@simonbs
simonbs / GitHub Sponsors Widget.js
Created January 31, 2022 15:19
Shows the total number of GitHub sponsors and the latest sponsors in a widget using the Scriptable app
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: brown; icon-glyph: hand-holding-usd;
// To use this script, you must create a personal access token on GitHub with the `read:org// scope.
// Follow the instructions on the link below to create your personal access token.
//
// https://github.com/settings/tokens
//
// Run the script when you ahve created your personal access token. It'll prompt you to enter the token and store it securely in the keychain on the device.