更改活动查找器选项卡

问题描述 投票:0回答:2

是否可以通过 applescript 更改活动的 Finder 选项卡?我想创建脚本来使用 cmd-[0-9] 更改选项卡。

对于 Safari,可以

set current tab to tab2
但 Finder 似乎并非如此。

applescript
2个回答
3
投票

是的。

每个应用程序支持的操作在 applescript 字典中定义。仅仅因为某些功能在一个内置应用程序中有效并不意味着它会转移到另一个内置应用程序中。

解决方案 1 是调用系统事件并调用上一个选项卡或下一个选项卡的按键。

解决方案 2:由于您想按位置引用选项卡,因此请使用 UI 脚本。这样,脚本可以切换到符合特定条件的任何选项卡。

tell application "System Events" to tell process "Finder" to tell window 1 to tell radio button 1 to click

0
投票

macOS Sonoma (14.0) 的更新版本:

tell application "System Events"
    tell application process "Finder"
        tell front window
            tell tab group 1
                tell first radio button
                    perform action "AXPress"
                end tell
            end tell
        end tell
    end tell
end tell

JXA版本:

const SystemEvents = Application("System Events");
const Finder = SystemEvents.applicationProcesses.byName("Finder");
const tabIndex = 0;
const mainWindow = Finder.windows().find(x =>
  x.attributes.byName("AXMain").value()
);
mainWindow.tabGroups
  .at(0)
  .radioButtons.at(tabIndex)
  .actions.byName("AXPress")
  .perform();
© www.soinside.com 2019 - 2024. All rights reserved.