首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过py-appscript访问Path Finder中的文件选择?

如何通过py-appscript访问Path Finder中的文件选择?
EN

Stack Overflow用户
提问于 2010-11-08 17:53:47
回答 2查看 1.1K关注 0票数 0

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

在applescript中,它类似于

代码语言:javascript
复制
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中,它应该是这样的:

代码语言:javascript
复制
from appscript import *
selectection_list = app('Path Finder').selection.get()   # returns reference, not string

那么,如何将selection_list中的引用转换为python字符串呢?

EN

回答 2

Stack Overflow用户

发布于 2010-11-09 02:18:55

我不熟悉Pathfinder,但如果它有自己的文件URL类型(或者可能是POSIX路径?),那么可能有某种分隔符来分隔路径中的文件层次结构级别。要在两者之间进行转换,您需要使用Applescript's text item delimiters。按照这些思路应该是可行的。

代码语言:javascript
复制
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的示例,那么我可以提供一个更好的答案。

票数 0
EN

Stack Overflow用户

发布于 2010-11-09 22:22:17

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4122750

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档