Skip to content

Instantly share code, notes, and snippets.

@griffin-stewie
Created August 28, 2022 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save griffin-stewie/4fe5a521c2c91ff62db1bdf7a2f06acb to your computer and use it in GitHub Desktop.
Save griffin-stewie/4fe5a521c2c91ff62db1bdf7a2f06acb to your computer and use it in GitHub Desktop.
Template for Shortcuts.app's Swift shell script. You can develop on Xcode Playground then you paste them into Shortcuts.app.
import Cocoa
import os
// print debug helper function for Playground envoironment and Shortcuts.app
func log(_ item: String, function: String = #function) {
let isRunningOnPlayground = CommandLine.arguments.filter({ !$0.isEmpty }).isEmpty
if isRunningOnPlayground {
Swift.print("\(function) \(item)")
} else {
NSLog("\(function) \(item)")
}
}
func main() {
if isRunningOnPlayground {
// You can change input as you like
let sampleInput = ["Contents.swift"]
run(input: sampleInput)
} else {
// Pass arguments
run(input: Array(CommandLine.arguments.suffix(from: 1)))
}
}
// Your script's entry point
func run(input: [String]) {
log("\(input)")
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment