MacOS如何使用Process Class执行需要输入密码的命令

How to use Process Class to execute commands need to enter password in MacOS

我想通过进程Class:

执行下面的命令
let uninstallTask = Process()
        uninstallTask.launchPath = "/bin/bash"
//MarkerPro is an app in launchpad
        uninstallTask.arguments = ["-c","sudo rm -rf "+"/Applications/MarkerPro.app"]
        uninstallTask.launch()

但出现以下错误: sudo:不存在 tty 且未指定 askpass 程序

所以在执行删除命令之前可能需要输入密码。

我通过使用 "STPrivilegedTask" 找到了解决方案,这是一个获得用户授权的工具。 使用 FileManager API 我觉得也是个好主意