macos运行程序
So, you want to run an external program (e.g., a shell program or script) from your SwiftUI macOS app, and a lot of the posts you’re seeing are from 30 B.C. So here’s something that worked for me on macOS, using Swift 5.2 and SwiftUI whatever the latest version is in 2020.
因此,您想从您的SwiftUI macOS应用程序运行一个外部程序(例如,shell程序或脚本),而您看到的很多帖子都来自公元前30年。这是使用Swift在macOS上对我有用的东西5.2和SwiftUI,无论最新版本是2020年。
There are three key steps here:
这里有三个关键步骤:
Use the Process Object to get your own task class
使用Process对象获取您自己的task类
Set its properties to prepare for launch 设置其属性以准备启动 Run it, and then capture the output of the program so you can, for example, show on your screen 运行它,然后捕获程序的输出,以便例如可以在屏幕上显示Well, hope that brightened your day.
好吧,希望您过得愉快。
You know what’s awesome about Apple’s dev docs regarding executableURL — it’s wonderful, there’s no documentation!
您知道Apple的executableURL URL很棒吗–太好了, 没有文档!
Tagged: swift for the slow
标记: 速度慢
翻译自: https://medium.com/macoclock/swift-5-2-run-external-program-from-your-swiftui-application-on-macos-96d2ebf75698
macos运行程序