0

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()

助言がありますか?

ありがとう!

PS: Snow Leopard を使用しています。

4

1 に答える 1

1

AppleScriptPython から実行可能なアプリケーションを扱う場合、ほとんど場合、Apple のScriptingBridgePyObjC. それを行う1つの方法:

from appscript import *
# move file to trash
app("Finder").move(mactypes.File(f.realpath),to=its.trash)
# get names of all items in the Trash
app("Finder").trash.items.name.get()
# move file x.txt from Trash to Desktop Folder
app("Finder").trash.files["x.txt"].move(to=its.desktop)

秘訣は、目的のファイルとフォルダーへの正しい Apple Event 参照を取得することです。少しごまかして、ごみ箱フォルダーへのパスを取得し、標準のファイル システム操作を使用する方が簡単な場合があります。

>>> app("System Events").trash.POSIX_path()
u'/Users/nad/.Trash'
于 2010-09-04T09:04:04.173 に答える