使用Applescript,我已经能够使用以下代码成功列出桌面上的文件夹作为选择:
set the_folder to (path to desktop)
tell application "Finder"
set foldernames to name of every folder of entire contents of the_folder
end tell
set theChosenOne to choose from list folder names
但是,当我尝试对/ Users文件夹执行相同的操作时:
set Users to "/Users"
set the_folder to Users
tell application "Finder"
set foldernames to name of every folder of entire contents of the_folder
end tell
set theChosenOne to choose from list foldernames
它返回此错误:错误“无法获取\”/ Users \“的全部内容。”编号-1728来自“/用户”的“类别”
搜索了该错误,但没有找到太多信息。感谢您的帮助,您可以给我这个。
答案 0 :(得分:2)
发生错误是因为Finder不支持斜杠分离的POSIX路径。
但是有一个更简单的解决方案。 path to users folder
返回alias
对/Users
文件夹的引用,可以直接使用。
set the_folder to path to users folder
tell application "Finder"
set foldernames to name of every folder of entire contents of the_folder
end tell
set theChosenOne to choose from list foldernames
警告:请注意entire contents
非常慢。 2分钟后,您将收到 Apple Event timed out 错误。您可以将Finder
tell块包装在with timeout
块中。但是,我建议使用shell的find
或mdfind
,这要快得多。而且很可能还会出现访问权限违规错误。