在mac os x上使用filemanager路径查找器,我想使用py-appscript通过python检索选定的文件/文件夹。py-appscript是一个高级事件桥,允许您从Python控制可脚本化的Mac应用程序。
在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字符串呢?
发布于 2010-11-09 02:18:55
我不熟悉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.加盐调味。但是,如果您可以提供一个PathFinder URL的示例,那么我可以提供一个更好的答案。
发布于 2010-11-09 22:22:17
你为什么不试试python-applescript,它可以通过python运行applescript的脚本。在这里获取:http://pypi.python.org/pypi/python-applescript
https://stackoverflow.com/questions/4122750
复制相似问题