如何通过 py-appscript 访问路径查找器中的文件选择?
在 mac os x 上使用文件管理器路径查找器,我想通过使用 py-appscript 使用 python 检索选定的文件/文件夹。 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
那么,我如何将选择列表中的引用转换为 python 字符串?
Using the filemanager Path Finder on mac os x, i wanna retrieve the selected files/folders with python by using py-appscript. py-appscript is a high-level event bridge that allows you to control scriptable Mac OS X applications from Python.
In applescript it would be something like
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
In python it would instead something like
from appscript import *
selectection_list = app('Path Finder').selection.get() # returns reference, not string
So, how can i convert the references in selection_list to python-strings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不熟悉 Pathfinder,但如果它有自己的文件 URL 类型(或者可能是 POSIX 路径?),那么可能存在某种分隔符来分隔路径中的文件层次结构级别。要在其中之一之间进行转换,您需要使用
Applescript 的文本项分隔符
。按照这些思路应该可以加盐调味。但是,如果您可以提供 PathFinder URL 的示例,那么我可以提供更好的答案。
I'm not familiar with Pathfinder, but if it has its own file URL type (or maybe it's a POSIX path?), then there is presumably a delimiter of some kind that separates the levels of file hierarchy in the path. To convert between one and the other, you need to work with
Applescript's text item delimiters
. Something along these lines should workAdd salt to taste. But, if you can provide an example of the PathFinder URL, then I can provide a better answer.
为什么不尝试一下 python-applescript,它可以通过 python 运行 applescript 的脚本。在这里获取它: http://pypi.python.org/pypi/python-applescript
Why don't you try python-applescript, it can run applescript's script thru python. Get it here : http://pypi.python.org/pypi/python-applescript