All Projects → a2 → Swift Shortcuts

a2 / Swift Shortcuts

Licence: mit
An iOS 14 Shortcuts creator written in Swift, inspired by SwiftUI.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Swift Shortcuts

Shortcuts Js
A JavaScript iOS 12 Shortcuts creator
Stars: ✭ 1,278 (+363.04%)
Mutual labels:  automation, apple, shortcuts
Shortcutsdirectory
A collection of user-submitted shortcuts for Shortcuts for iOS.
Stars: ✭ 376 (+36.23%)
Mutual labels:  automation, apple
Aquatouch
Dynamic Custom Macros for your MacBook TouchBar! (Supports 40+ Apps and Websites)
Stars: ✭ 125 (-54.71%)
Mutual labels:  automation, apple
Amazon Fresh Whole Foods Delivery Slot Finder
A Mac tool that finds available delivery slots for Amazon's Whole Foods delivery and Amazon Fresh services
Stars: ✭ 1,048 (+279.71%)
Mutual labels:  automation, apple
iOS-Shortcuts-Reference
Reference documentation for the iOS Shortcuts app file structure
Stars: ✭ 89 (-67.75%)
Mutual labels:  apple, shortcuts
Node Applesign
NodeJS module and commandline utility for re-signing iOS applications (IPA files).
Stars: ✭ 261 (-5.43%)
Mutual labels:  apple
Jenkins Bootstrap Shared
Jenkins as immutable infrastructure made easy. A repository of shared scripts meant to be used as a git submodule. Packing Jenkins, plugins, and scripts into immutable packages and images.
Stars: ✭ 270 (-2.17%)
Mutual labels:  automation
Zsh Apple Touchbar
Make your touchbar more powerful.
Stars: ✭ 261 (-5.43%)
Mutual labels:  apple
Pywhatsapp
Python Automation using selenium & Scheduling of messages and media
Stars: ✭ 257 (-6.88%)
Mutual labels:  automation
Swiftrex
Swift + Redux + (Combine|RxSwift|ReactiveSwift) -> SwiftRex
Stars: ✭ 267 (-3.26%)
Mutual labels:  apple
Cli
🆑📍 Setup automated semver compliant package publishing
Stars: ✭ 272 (-1.45%)
Mutual labels:  automation
Fw
workspace productivity booster
Stars: ✭ 269 (-2.54%)
Mutual labels:  automation
Decker
Declarative penetration testing orchestration framework
Stars: ✭ 263 (-4.71%)
Mutual labels:  automation
Web crawlers
I was always intrigued whenever I see how someone can automate a task with a few lines of code. Here are some interesting Python scripts that lets you automate various daily tasks.
Stars: ✭ 270 (-2.17%)
Mutual labels:  automation
Roguesploit
Powerfull Wi-Fi trap!
Stars: ✭ 262 (-5.07%)
Mutual labels:  automation
Playwright Go
Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
Stars: ✭ 272 (-1.45%)
Mutual labels:  automation
2018
Student submissions for the WWDC 2018 Scholarship
Stars: ✭ 261 (-5.43%)
Mutual labels:  apple
Fate Grand Order lua
Fate Grand Order auto battle script - no root needed, for Android use only
Stars: ✭ 266 (-3.62%)
Mutual labels:  automation
Swiftui Charts
🚀 SwiftUI Charts with custom styles
Stars: ✭ 272 (-1.45%)
Mutual labels:  apple
Mac Setup
🛠️ Front end web development setup for macOS.
Stars: ✭ 265 (-3.99%)
Mutual labels:  apple

SwiftShortcuts

An iOS 14 Shortcuts creator written in Swift, inspired by SwiftUI.

Installation

SwiftShortcuts is distributed using the Swift Package Manager. To install it into a project, add it as a dependency within your Package.swift manifest:

let package = Package(
    ...
    dependencies: [
        .package(url: "https://github.com/a2/swift-shortcuts.git", from: "1.0.0")
    ],
    ...
)

Then import SwiftShortcuts in your project wherever you'd like to use it:

import SwiftShortcuts

Getting Started

SwiftShorcuts was inspired by SwiftUI and, just as every SwiftUI View is made from other View types, so too is every Shortcut built from other Shortcut types. The only requirement of the Shortcut protocol is an instance property named body whose type is another Shortcut:

/// A type that represents a user workflow, or a part of one, in the Shortcuts app.
public protocol Shortcut {
    /// The type of shortcut representing the body of this shortcut.
    ///
    /// When you create a custom shortcut, Swift infers this type from your
    /// implementation of the required `body` property.
    associatedtype Body: Shortcut

    /// The contents of the shortcut.
    var body: Body { get }
}

To start writing your own shortcut, create a type (such as a struct) that conforms to the Shortcut protocol. At first, return a Comment with some "Hello, world!" text.

// main.swift

struct HelloWorldShortcut: Shortcut {
    var body: some Shortcut {
        Comment("Hello, world!")
    }
}

To create a file that you can import into the Shortcuts app, call the build() function on your shortcut and write the Data to a file.

// continued from above

let shortcut = HelloWorldShortcut()
let data = try shortcut.build()
try data.write(to: URL(fileURLWithPath: "Hello World.shortcut"))

Now you can share (for example, via AirDrop) the Hello World.shortcut file to your device and it will open in the Shortcuts app. Unfortunately iOS 13 does not support opening serialized .shortcut files.

Examples

Warn for Low Battery Level

Saves the output of BatteryLevel shortcut to an OutputVariable and later references that value in a ShowResult shortcut.

// Swift 5.2
import SwiftShortcuts

struct BatteryLevelShortcut: Shortcut {
    @OutputVariable var batteryLevel: Variable

    var body: some Shortcut {
        ShortcutGroup {
            Comment("This Shortcut was generated in Swift.")
            BatteryLevel()
                .savingOutput(to: $batteryLevel)
            If(batteryLevel < Number(20), then: {
                SetLowPowerMode(true)
                ShowResult("Your battery level is \(batteryLevel)%; you might want to charge soon.")
            }, else: {
                ShowResult("Your battery level is \(batteryLevel)%; you're probably fine for now.")
            })
        }
    }
}

Clap Along

Takes advantage of the usingResult() function to chain shortcut outputs to shortcut inputs.

// Swift 5.2
import SwiftShortcuts

struct ClapAlongShortcut: Shortcut {
    var body: some Shortcut {
        ShortcutGroup {
            Comment("This Shortcut was generated in Swift.")
            AskForInput(prompt: "WHAT 👏 DO 👏 YOU 👏 WANT 👏 TO 👏 SAY")
                .usingResult { providedInput in
                    ChangeCase(variable: providedInput, target: .value(.uppercase))
                }
                .usingResult { changedCaseText in
                    ReplaceText(variable: changedCaseText, target: "[\\s]", replacement: " 👏 ", isRegularExpression: true)
                }
                .usingResult { updatedText in
                    ChooseFromMenu(items: [
                        MenuItem(label: "Share") {
                            Share(input: updatedText)
                        },
                        MenuItem(label: "Copy to Clipboard") {
                            CopyToClipboard(content: updatedText)
                        },
                    ])
                }
        }
    }
}

Shorten with small.cat

A more complicated example that temporarily shortens a URL or some text with the small.cat service.

// Swift 5.2
import SwiftShortcuts

struct ShortenWithSmallCatShortcut: Shortcut {
    @OutputVariable var url: Variable
    @OutputVariable var expiry: Variable

    var body: some Shortcut {
        ShortcutGroup {
            GetType(input: .shortcutInput)
                .usingResult { type in
                    If(type == "URL", then: {
                        Text("\(.shortcutInput)")
                    }, else: {
                        GetClipboard()
                    })
                }
                .usingResult { ifResult in
                    URLEncode(input: "\(ifResult)")
                }
                .savingOutput(to: $url)

            ChooseFromMenu(prompt: "Expires in:", items: [
                    MenuItem(label: "10 minutes") {
                        Text("10")
                    },
                    MenuItem(label: "1 hour") {
                        Text("60")
                    },
                    MenuItem(label: "1 day") {
                        Text("1440")
                    },
                    MenuItem(label: "1 week") {
                        Text("10080")
                    },
                ])
                .savingOutput(to: $expiry)

            GetContentsOfURL(method: .POST, url: "https://small.cat/entries", body: .form([
                "entry[duration]": "\(expiry)",
                "entry[value]": "\(url)",
                "utf8": "✓",
            ])).usingResult { contents in
                GetURLsFromInput(input: "\(contents)")
            }.usingResult { urls in
                FilterFiles(input: urls, filters: .all([
                    NameFilter(beginsWith: "http://small.cat/"),
                    NameFilter(isNot: "http://small.cat/"),
                ]), limit: 1)
            }.usingResult { url in
                ChooseFromMenu(items: [
                    MenuItem(label: "Copy") {
                        CopyToClipboard(content: url)
                    },
                    MenuItem(label: "Share") {
                        Share(input: url)
                    },
                    MenuItem(label: "Show") {
                        ShowAlert(title: "Small.cat", message: "\(url)", showsCancelButton: false)
                    },
                ])
            }
        }
    }
}

Design and Goals

SwiftShortcuts began as the similarly named ShortcutsSwift and was originally inspired by Shortcuts JS. Both SwiftShortcuts, and ShortcutsSwift before it, aimed to be in Swift what Shortcuts JS is for JavaScript.

The goal of this iteration of SwiftShortcuts is to make writing Shortcuts app workflows in Swift as easy as composing Views in SwiftUI. As you can see above, even the base Shortcut protocol is heavily inspired by SwiftUI's View protocol.

This repository does not contain every possible Shortcuts-supported action or every possible permutation of parametres for those shortcuts. Please feel free to contribute missing shortcut types and even test cases.

License

SwiftShortcuts is available under the MIT license. See the LICENSE file for more info.

Contributions and Support

Inspired by the support model behind Publish.

SwiftShortcuts is developed completely in the open, and your contributions are more than welcome.

This project does not come with GitHub Issues-based support, and users are instead encouraged to become active participants in its continued development — by fixing any bugs that they encounter, or by improving the documentation wherever it's found to be lacking.

If you wish to make a change, open a Pull Request — even if it just contains a draft of the changes you're planning, or a test that reproduces an issue — and we can discuss it further from there.

Hope you'll enjoy using SwiftShortcuts!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].