我正在运行 OS X 10.6,我想使用 applescript 在搜索打开时单击 Finder 窗口的“文件名”单选按钮。(默认为“内容”)
我使用了 UI 浏览器(见下文)并找到了一条路径,但 Applescript 给出了一些错误,所以我肯定做错了什么。我已将我的代码和屏幕截图发布在下面:
代码:
tell application "System Events"
activate application "Finder"
click checkbox "File Name" of radio group 1 of group 1 of splitter group 1 of window 1 of application "Finder"
end tell
屏幕截图:
来自 UIElementInspector 的代码
<AXApplication: “Finder”>
<AXWindow: “Searching “UIElementInspector””>
<AXSplitGroup>
<AXGroup>
<AXRadioGroup>
<AXCheckBox: “File Name”>
Attributes:
AXRole: “AXCheckBox”
AXRoleDescription: “check box”
AXHelp: “(null)”
AXValue: “1”
AXEnabled: “1”
AXFocused (W): “0”
AXParent: “<AXRadioGroup>”
AXWindow: “<AXWindow: “Searching “UIElementInspector””>”
AXTopLevelUIElement: “<AXWindow: “Searching “UIElementInspector””>”
AXPosition: “x=1357 y=149”
AXSize: “w=75 h=17”
AXTitle: “File Name”
Actions:
AXPress - press
答案1
一些更差的 UI 脚本:
tell application "System Events" to tell process "Finder"
set frontmost to true
click menu bar 1's menu bar item "File"'s menu 1's menu item "Find"
tell application "Finder"
set toolbar visible of window 1 to false
set bounds of window 1 to {0, 22, 960, 587}
end tell
tell window 1's splitter group 1
click group 1's radio group 2's checkbox "File Name"
click group 1's radio group 1's radio button "This Mac"
click scroll area 1's outline 1's group 1's button 1 -- sort by Name
click group 2's pop up button 1
keystroke "sys" & return
click group 2's pop up button 2
keystroke "are " & return
end tell
end tell
由于某种原因,在我的 10.6.7 上checkbox "File Name"
是用radio group 2
而不是radio group 1
。
答案2
答案3
Apple 再次改变了搜索方式,现在按文件名搜索非常复杂,您必须点击自动隐藏的下拉菜单,当您按回车键时,该下拉菜单就会消失。恢复下拉菜单的唯一方法是删除一个字母并重新输入。
无论如何,以下 AppleScript 对我有用:
on run {input, parameters}
tell application "System Events" to tell process "Finder"
set frontmost to true
click menu bar 1's menu bar item "File"'s menu 1's menu item "Find"
tell application "Finder"
end tell
tell window 1's splitter group 1
click group 2's pop up button 1
click menu item "Name" of menu 1 of pop up button 1 of group 2
click group 2's pop up button 2
click menu item "contains" of menu 1 of pop up button 2 of group 2
end tell
end tell
return input
end run
我想知道在 applescript 中是否有一种方法可以自动在搜索前面添加“name:”,这样我们就不必总是使用 command-F 来按名称搜索?