Scriptable will allow you to run and automate your daily basis Terminal tasks through a macOS app.
public protocol Scriptable {
typealias ScriptResponce = (command: String, errorOutput: String?, dataOutput: String)
/// The command you want to execute through your terminal
///
/// Keep in mind if you pass any aurgument with a space like:
/// `open -a Some Application`
/// you will need to remove the spaces between the app name "Some Application"
var command: String { get }
/// Run the task throue the terminal
///
/// - Returns: The output string for (command: String, errorOutput: String?, dataOutput: String)
@discardableResult func runTask(launchPath: String) -> ScriptResponce
}
enum MySimpleCommands: Scriptable {
case openDesktop
var command: String {
switch self {
case .openDesktop:
return "cd ~ && cd Desktop/ && open ."
}
}
}
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
MySimpleCommands.openDesktop.runTask() // This will open your desktop folder
}
}
Scriptable provide a bunch of ready made tasks like: Network tasks, App tasks, Directory tasks and also you can run your random task through Custom task
Make sure you import Scriptable
import Scriptable
And inside any method you can say:
Task.Network.getSecureWebProxyInfo.runTask()
Note that runTask()
marked as @discardableResult
so it's actually returns some values like:
command: String
errorOutput: String?
dataOutput: String
You also can get access to those values to display them if you want to build a small Terminal app or for debugging purpose:
Task.Network.getSecureWebProxyInfo.runTask().dataOutput
There is an example project thats allows you to turn on/off the proxy, simpl clone the repo, and run pod install
from the Example directory first.
Make sure to disable App Sandbox in your Cocoa Application (found under your Project app target > Capabilities tab > App Sandbox switch). If you didn't disable it you'll find that you're being blocked by a sandbox exception.
Scriptable is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Scriptable'
cs4alhaider, cs.alhaider@gmail.com
Scriptable is available under the MIT license. See the LICENSE file for more info.