0

使用 mac os x 上的文件管理器路径查找器,我想使用 python 检索选定的文件/文件夹py-appscript。py-appscript 是一个高级事件桥,允许您从 Python 控制可编写脚本的 Mac OS X 应用程序。

在applescript中它会像

tell application "Path Finder"
 set selection_list to selection -- list of fsItems (fsFiles and fsFolders)
 set _path to posix path of first item of selection_list
 do shell script "python " & quoted form of _path
end tell

在python中,它会改为

from appscript import *
selectection_list = app('Path Finder').selection.get()   # returns reference, not string

那么,如何将 selection_list 中的引用转换为 python-strings?

4

2 回答 2

0

你为什么不试试python-applescript,它可以通过python运行applescript的脚本。在这里获取:http: //pypi.python.org/pypi/python-applescript

于 2010-11-09T14:22:17.047 回答
0

我不熟悉 Pathfinder,但如果它有自己的文件 URL 类型(或者它可能是 POSIX 路径?),那么可能有某种分隔符将路径中的文件层次结构的级别分开。要在一个和另一个之间进行转换,您需要使用Applescript's text item delimiters. 这些方面的东西应该起作用

set thePathFinderPath to "/pathfinder/path/to/finder"

set pathFinderPathDelimiter to "/" -- whatever it may be here
set finderPathDelimiter to ":"

set AppleScript's text item delimiters to {pathFinderPathDelimiter}
set thePathComponents to (get every text item in thePathFinderPath) as list
set AppleScript's text item delimiters to {finderPathDelimiter}
set theFinderPath to thePathComponents as text
set AppleScript's text item delimiters to "" -- very important you clear the TIDs.

加盐调味。但是,如果您可以提供路径查找器 URL 的示例,那么我可以提供更好的答案。

于 2010-11-08T18:18:55.323 回答