Mac OS X Python GUI 管理员提示符
我有一个 OS X Python 应用程序,它使用 wxPython 作为 GUI 控件。我希望在启动网络服务之前提示用户获得管理权限(类似于使用 Objective-C 中的授权服务 API)。
我发现的最接近的库是 Bob Ippolito 的 授权库,但它相当过时并且具有兼容性Snow Leopard (OS X 10.6.4 / Python 2.6.4) 的问题。
我的解决方法是创建一个 Objective-C 启动器,以管理权限运行 python 应用程序,但这感觉相当笨拙。
感谢您的帮助!
I have an OS X Python application that uses wxPython for it's GUI controls. I'm looking to prompt the user for administrative rights (akin to using the Authorization Service API in Objective-C) before starting a network service.
The closest library I have found is Bob Ippolito's Authorization library but it is fairly outdated and has compatibility issues with Snow Leopard (OS X 10.6.4 / Python 2.6.4).
My workaround would be to create an Objective-C launcher that runs the python application with administrative rights but that feels fairly kludgy.
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您需要运行的只是一个 shell 命令,请求提升权限,那么您可以这样做:
它将在 applescript 解释器中运行 shell 命令并提示用户输入其帐户凭据;使用 sudo 有效运行命令。
请注意,您会在命令中享受转义引号的乐趣,例如
希望有帮助!
If it's just a shell command that you need to run, requesting elevated privileges, then you can do this:
It will run a shell command within the applescript interpreter and prompt the user for their account credentials; effectively running the command using sudo.
Note that you'll have fun escaping quotes within your command, e.g.
Hope that helps!
您可以使用 Platypus 将整个脚本变成本机 Mac OS X 应用程序,从而以管理员权限运行整个脚本。
You could run your entire script with admin privileges by making it into a native Mac OS X application using Platypus.
您可能想检查此处发布的另一个问题的答案:我应该使用哪种 API 将用户权限提升为 Mac OS X 中的超级用户?
You might want to check the answer to another question posted here: What kind of API should I use to elevate user privilege to super-user in a Mac OS X?
以下是如何运行“ls”命令并询问密码
Here is how to run "ls" command and ask for the password