【问题标题】:Select multiple subfolders in one Finder windows在一个 Finder 窗口中选择多个子文件夹
【发布时间】:2014-08-21 15:45:20
【问题描述】:
在我的 applescript 中,我试图选择所选文件夹中的所有子文件夹。该脚本似乎成功地选择了想要的子文件夹,但是根据它们的父文件夹将它们分别放在多个单独的窗口中。有没有办法强制它们在一个窗口中打开(就像您在列表视图中展开文件夹并cmd单击以从多个文件夹中选择子文件夹一样)?
谢谢,
潘
这是代码,以防万一。
tell application "Finder"
set SelectedFolders to selection
set i to 1
set NewSelection to {}
repeat with aFolder in SelectedFolders
repeat with bFolder in aFolder
copy bFolder to the end of NewSelection
end repeat
end repeat
select every item of NewSelection
end tell
【问题讨论】:
标签:
select
applescript
directory
【解决方案1】:
您可以尝试“设置选择”而不是“选择”。前面的 Finder 窗口必须在列表视图中,并且必须已经展开相应的文件夹。基本上,如果您尝试选择的内容在前面的 Finder 窗口中不可见,那么它将不起作用。
set selection to NewSelection
我不知道以编程方式扩展文件夹的方法。但是,您可以使用此方法确保 Finder 窗口处于列表视图中...
set current view of Finder window 1 to list view
我认为你正在尝试做的事情将被证明是困难的。在我的简短测试中,我无法让它始终如一地工作。祝你好运。
【解决方案2】:
我不会依赖这个...
tell application "Finder"
set SelectedFolders to selection
if SelectedFolders = {} then return
set current view of Finder window 1 to list view
my rightArrow()
set NewSelection to {}
repeat with aFolder in SelectedFolders
set NewSelection to NewSelection & folders of aFolder
end repeat
if NewSelection ≠ {} then
set selection to NewSelection
my rightArrow()
end if
end tell
on rightArrow()
activate application "Finder"
tell application "System Events"
tell process "Finder"
key code 124
end tell
end tell
end rightArrow