Skip to content

MacOS library that allow you to run your Terminal commands through macOS apps

License

Notifications You must be signed in to change notification settings

cs4alhaider/Scriptable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scriptable

CI Status Version License Platform

Scriptable will allow you to run and automate your daily basis Terminal tasks through a macOS app.

Scriptable protocol

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
}

Simple Example

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 Task

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

Here is an example on how to get it:

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

Example

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.

Requirements

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.

Installation

Scriptable is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Scriptable'

Author

cs4alhaider, cs.alhaider@gmail.com

License

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

About

MacOS library that allow you to run your Terminal commands through macOS apps

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published