Created
August 28, 2022 14:55
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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