使用 Applescript 循环递归应用视图选项
我正在尝试改进 Applescript 来设置 Finder 窗口视图 - 递归 - 与任何给定文件夹中可能存在的深度一样多。我可以达到预期的结果,但只能在一个窗口/文件夹中;尽管经过数小时的搜索和实验,我仍然无法理解 Applescript 看似简单的语法(相对于变量,尤其是循环)。顺便说一句,我的预期用途是作为留在 Dock 中的 Droplet,或者创建一些变体并将它们添加到 Finder 窗口工具栏。另外,即使这最终需要打开每个文件夹和子文件夹,这对我来说也是可以接受的,因为我不会经常在文件层次结构中太高的位置运行它。非常感谢您对此提供的任何帮助。
这对于前面的窗口工作得很好:
tell application "Finder"
activate
set toolbar visible of front window to false
set bounds of front window to {0, 43, 899, 855}
set current view of front window to list view
set visible of column id name column of list view options of front window to true
set sort column of list view options of front window to name column
set visible of column id version column of list view options of front window to false
set visible of column id label column of list view options of front window to false
set width of column id name column of list view options of front window to 300
set width of column id modification date column of list view options of front window to 111
set width of column id creation date column of list view options of front window to 111
set width of column id size column of list view options of front window to 90
set width of column id kind column of list view options of front window to 180
set uses relative dates of the list view options of front window to false
set calculates folder sizes of the list view options of front window to true
end tell
...这只是我最近一次尝试将上面的内容包装在重复循环中...但我是一个菜鸟,并且越来越对 Applescript 相对于循环、变量的简单语法感到困惑。
tell application "Finder"
activate
set parentFolder to the front Finder window
repeat with entire contents in parentFolder
[ same 'set' commands here ]
end repeat
end tell
I'm trying to advance an Applescript to set Finder window views - recursively - as many levels deep as there may be in any given folder. I can achieve the desired results but only in one window/folder; despite hours of searching and experimenting I'm still unable to wrap my noob head around Applescript's seemingly simple syntax (vis a vis variables and especially loops). By the way, my intended usage for this is as a droplet to leave in the Dock, or perhaps to create some variations and add them to the Finder window Toolbar. Also, even if this ultimately requires opening every folder and subfolder, that would be acceptable to me since I wouldn't be running it at too high in the file hierarchy too often. Many thanks in advance for any help with this.
This works fine for the front Window:
tell application "Finder"
activate
set toolbar visible of front window to false
set bounds of front window to {0, 43, 899, 855}
set current view of front window to list view
set visible of column id name column of list view options of front window to true
set sort column of list view options of front window to name column
set visible of column id version column of list view options of front window to false
set visible of column id label column of list view options of front window to false
set width of column id name column of list view options of front window to 300
set width of column id modification date column of list view options of front window to 111
set width of column id creation date column of list view options of front window to 111
set width of column id size column of list view options of front window to 90
set width of column id kind column of list view options of front window to 180
set uses relative dates of the list view options of front window to false
set calculates folder sizes of the list view options of front window to true
end tell
... and here's just my latest attempt to wrap the above in a repeat loop ... but I'm a noob and increasingly confused by Applescript's otherwise simple syntax vis a vis loops, variables.
tell application "Finder"
activate
set parentFolder to the front Finder window
repeat with entire contents in parentFolder
[ same 'set' commands here ]
end repeat
end tell
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您可能已经阅读了 AppleScript:初学者教程。
既然你还没有收到任何回复,我会尽力回答。我对 AppleScript 不太熟悉,而且此时无法使用 Mac。我曾经经常使用 HyperTalk(在旧的 HyperCard 中,在 System 7 上),AppleScript 就是基于它的。
我尝试考虑在 Finder 窗口工具栏中安装或将一个或多个文件或文件夹拖放到脚本图标上的可能性。
编辑:
我假设 Finder 可以在不打开每个文件夹的情况下设置视图属性。如果我要更改此设置以打开每个文件夹,我可能希望确保脚本打开的每个窗口在下一个窗口打开之前关闭。不过,我认为对于大量文件夹来说,它仍然会陷入困境。
也许对深嵌套或长列表进行错误检查是明智的,然后在开始之前提示用户进行确认。包含一种中止脚本的好方法也很重要,最好是通过进度对话框中的取消按钮。
It sounds like you may have been reading AppleScript: Beginner's Tutorial.
Since you haven't received any replies yet, I'll try to answer. I'm not very familiar with AppleScript and don't have access to a Mac at this hour. I used to use HyperTalk (in ye olde HyperCard, on System 7) a lot, which AppleScript was based on.
I've tried to account for the possibilities of installing in the Finder window toolbar or dropping one or more files or folders on the script icon.
EDIT:
I've assumed the Finder makes it possible to set view attributes without opening each folder. If I were to change this to open each folder, I would probably want to ensure that each window the script opened was closed before the next one opened. I think it would still bog down for large numbers of folders, though.
Perhaps an error-check for deep nests or long lists would be wise, which would then prompt the user for confirmation before starting. Would also be important to include a nice way abort the script, preferably via a cancel button in a progress dialog.