2

I would like enable AppleScript to reveal a particular tab within a custom preference pane I am developing, so that this works:

tell application "System Preferences" 
  reveal anchor "Foo" of pane id "com.example.preferences.Bar"
end tell

I cannot find anywhere how my preference pane would declare or specify the "Foo" anchor or associate that with any particular tab view item.

4

2 回答 2

1

对于任何因我所做的挫折而来到这个问题的人,我在这里记录了能够为您的 custom 获取锚点的步骤NSPreferencePane

最大的提示来自@geowar:

谷歌 GPGPreferences.searchTerms 字典revealElementForKey 获取一些线索……(AFAIK 这在任何地方都没有记录……)

我第一次来这个问题时忽略了这个评论,第二次我查看GPGPreferences.m文件时,更具体地说是revealElementForKey方法,但无法弄清楚函数实际上是如何被调用的。

关键字是searchTerms

当我终于找到这篇文章SearchablePreferencePanes时,我才意识到这一点。

脚步:

  1. 将一个NSPrefPaneSearchParameters键添加到Info.plist您的首选项窗格捆绑包中,其值类似于MyPreferencePane.
  2. 创建一个MyPreferencePane.searchTerms在您的 Xcode 项目中调用的文件。该文件的内容应该是一个属性列表,其中包含一个类似于下面的字典(取自Sound首选项窗格)。这不仅允许用户在搜索指定术语时获得您的首选项窗格的命中,而且还将为首选项窗格生成锚点
  3. revealElementForKey(key: String)在您的类中实现继承自NSPreferencePane. 当用户在搜索术语后打开窗格时以及在调用reveal()ScriptingBridge 锚类的方法时都会调用此方法。
  4. 繁荣!

享受生活。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>effects</key>
    <dict>
        <key>localizableStrings</key>
        <array>
            <dict>
                <key>comments</key>
                <string>Localizable index words</string>
                <key>index</key>
                <string>noises, audio, hear, level, volume, louder, softer, quieter, increase, decrease, raise, lower, speaker, beep, warning, bell, ding, ring, hearing, beeping, dinging, ringing</string>
                <key>title</key>
                <string>Alerts and sound effects</string>
            </dict>
            <dict>
                <key>comments</key>
                <string>Localizable index words</string>
                <key>index</key>
                <string>audio, hear, level, volume, louder, softer, quieter, increase, decrease, raise, lower, music, speakers, hearing</string>
                <key>title</key>
                <string>Sound volume</string>
            </dict>
            <dict>
                <key>comments</key>
                <string>Localizable index words</string>
                <key>index</key>
                <string>audio, hear, level, volume, louder, softer, quieter, increase, decrease, raise, lower, quiet, silent, silence, turn off, hearing, muting</string>
                <key>title</key>
                <string>Mute the sound</string>
            </dict>
            <dict>
                <key>comments</key>
                <string>Localizable index words</string>
                <key>index</key>
                <string>menubar</string>
                <key>title</key>
                <string>Show volume in menu bar</string>
            </dict>
        </array>
    </dict>
    <key>input</key>
    <dict>
        <key>localizableStrings</key>
        <array>
            <dict>
                <key>comments</key>
                <string>Localizable index words</string>
                <key>index</key>
                <string>audio, hear, level, volume, louder, softer, quieter, increase, decrease, raise, lower, devices, sources, microphones, instruments, MIDI, record, line in, hearing, recording</string>
                <key>title</key>
                <string>Sound input</string>
            </dict>
        </array>
    </dict>
    <key>output</key>
    <dict>
        <key>localizableStrings</key>
        <array>
            <dict>
                <key>comments</key>
                <string>Localizable index words</string>
                <key>index</key>
                <string>devices, headphones, headsets, speakers, hear, balance, hearing, head phones, head sets</string>
                <key>title</key>
                <string>Sound output</string>
            </dict>
            <dict>
                <key>comments</key>
                <string>Localizable index words</string>
                <key>index</key>
                <string>airplay, speakers</string>
                <key>title</key>
                <string>AirPlay audio streaming</string>
            </dict>
        </array>
    </dict>
</dict>
</plist>
于 2016-01-14T21:35:33.060 回答
1

首先,您必须确保您搜索的是锚点,而不是其他类型的对象。然后使用下面的脚本来获取每个锚名称:(在此示例中,获取声音首选项的锚将给出“输出”、“输入”、..)

tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.sound"
get the name of every anchor of current pane
end tell
于 2015-11-04T16:19:27.740 回答