Scriptable 0.1.5

Scriptable 0.1.5

Abdullah Alhaider 维护。



Scriptable

CI Status Version License Platform

Scriptable 允许您通过 macOS 应用程序运行和自动化日常的终端任务。

Scriptable 协议

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 任务

Scriptable 提供了一系列现成的任务,例如:网络任务、应用任务、目录任务,也可以通过自定义任务运行随机任务。

以下是一个获取它的示例

请确保您已经导入了 Scriptable

import Scriptable

然后在任何方法内部,您可以说

Task.Network.getSecureWebProxyInfo.runTask()

请注意,runTask() 被标记为 @discardableResult,因此它实际上返回一些值,例如

  • 命令:String
  • 错误输出:String?
  • 数据输出:String

您还可以获取这些值,以便在需要构建小型终端应用或进行调试时对其进行显示。

Task.Network.getSecureWebProxyInfo.runTask().dataOutput

示例

有一个示例项目,你可以用它来开启/关闭代理,简化克隆仓库,以及首先从示例目录运行pod install

要求

确保在您的Cocoa应用程序中禁用App沙箱(在您的项目 > 应用程序目标 > 能力选项卡 > 应用沙箱开关下找到)。如果您没有禁用它,您会发现您被沙箱异常阻止了。

安装

Scriptable可以通过CocoaPods获得。要安装它,只需将以下行添加到您的Podfile中

pod 'Scriptable'

作者

cs4alhaider, [email protected]

许可协议

Scriptable采用MIT许可协议提供。有关更多信息,请参阅LICENSE文件。