通过 PyObjC 在 Mac OS X 中使用 ScriptingBridge 恢复垃圾项
我正在尝试找出一种通过 PyObjC 使用 ScriptingBridge 恢复(放回)垃圾项的方法。
from AppKit import NSURL
from ScriptingBridge import SBApplication
targetfile = NSURL.fileURLWithPath_(f.realpath)
finder = SBApplication.applicationWithBundleIdentifier_("com.apple.Finder")
trash_items = finder.trash.items()
任何建议?
谢谢!
附: 我用的是雪豹。
I'm trying to figure out a way to restore (Put Back) Trash Item using ScriptingBridge via PyObjC.
There isn't enough documentation here
from AppKit import NSURL
from ScriptingBridge import SBApplication
targetfile = NSURL.fileURLWithPath_(f.realpath)
finder = SBApplication.applicationWithBundleIdentifier_("com.apple.Finder")
trash_items = finder.trash.items()
Any suggestions?
Thanks!
PS:
I'm using Snow Leopard.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当从 Python 处理支持
AppleScript
的应用程序时,您几乎总是会发现使用 appscript 而不是 Apple 的ScriptingBridge
或PyObjC
。一种方法是:诀窍是获取所需文件和文件夹的正确 Apple 事件引用。作弊一下并获取垃圾文件夹的路径并对其使用标准文件系统操作可能更容易:
When dealing with
AppleScript
-able applications from Python, you will almost always find it easier to use appscript rather than Apple'sScriptingBridge
orPyObjC
. One way to do it:The trick is getting the right Apple Event reference to the desired files and folders. It may be even easier to cheat a bit and get the path to the trash folder and use standard file system operations on it: