Applescript 正在/用户中列出文件夹

Applescript 正在/用户中列出文件夹,applescript,Applescript,使用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 但是,当我尝试对/User

使用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”的«类ects»中获取“/Users”编号-1728的全部内容”


搜索了那个错误,但没有找到多少信息。感谢您在这方面给我的任何帮助。

出现错误是因为查找程序不支持斜杠分隔的POSIX路径

但有一个更简单的解决方案
path to users文件夹
返回对文件夹/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

警告:请注意
整个内容的速度非常慢。2分钟后,您将收到一个Apple事件超时错误。您可以将
Finder
tell块包装在带有超时的
块中。不过,我建议使用shell的
find
mdfind
,它们的速度要快得多。而且很可能还会出现访问权限冲突错误。

发生此错误的原因是查找程序不支持斜杠分隔的POSIX路径

但有一个更简单的解决方案
path to users文件夹
返回对文件夹
/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

警告:请注意
整个内容的速度非常慢。2分钟后,您将收到一个Apple事件超时错误。您可以将
Finder
tell块包装在带有超时的
块中。不过,我建议使用shell的
find
mdfind
,它们的速度要快得多。而且很可能您也会遇到访问权限冲突错误。

就是这样,谢谢!开始时出错,但在第一行添加了括号,结果成功了。你对“全部内容”的看法是对的,在这种情况下,不需要将它们删除得如此之多,而且,是的,它运行得更快。再次感谢!成功了,谢谢!开始时出错,但在第一行添加了括号,结果成功了。你对“全部内容”的看法是对的,在这种情况下,不需要将它们删除得如此之多,而且,是的,它运行得更快。再次感谢!使用
do shell script
find/Users-maxdepth 1-type d
可能会有一些运气。使用
do shell script
find/Users-maxdepth 1-type d
可能会有一些运气,可能会先在终端中尝试。