【问题标题】:Applescript - Set value of System Preferences dock size slider on MacOS MontereyApplescript - 在 MacOS Monterey 上设置系统偏好设置底座大小滑块的值
【发布时间】:2022-01-18 11:50:35
【问题描述】:

我正在尝试使用 AppleScript 将扩展坞大小更改为指定值。我的操作系统是 MacOS Monterey v12.0,这可能很重要。

我能够掌握适当的“Dock Size”滑块,但我不知道如何直接设置它的值。

鉴于我在 tell slider 块中,我已经尝试过......

  • set value to targetValue
  • set value of value indicator 1 to targetValue
  • 在设置之前用set focused to true 对焦(没有区别)

使用increment/decrement

repeat while value is less than targetValue
    increment
end repeat
repeat while value is greater than targetValue
    decrement
end repeat

...但这是非常不精确的,最终将值设置在一个不够精确的范围内。


我的完整脚本如下。我从命令行调用它

$ osascript -s eo /path/to/file/Resize-Dock.applescript 0.3

调整大小-Dock.applescript

#!/usr/bin/osascript

on run argv

    set targetValue to item 1 of argv 

    if running of application "System Preferences" then
        quit application "System Preferences"
        delay 1
    end if

    tell application "System Preferences"
        activate
        reveal pane id "com.apple.preference.dock"
        delay 1
        
        tell application "System Events"
            
            tell slider 1 of group 1 of window "Dock & Menu Bar" of application process "System Preferences"
                                
                set currentValue to value of value indicator 1
                log "  Dock size value BEFORE = " & currentValue
            
                set focused to true
                
                ######## HERE IS WHERE I NEED HELP PLEASE ########
                set value of value indicator 1 to targetValue
                
                set currentValue to value of value indicator 1
                log "  Dock size value AFTER = " & currentValue
                
            end tell
            
        end tell
    
    end tell

    if running of application "System Preferences" then
        quit application "System Preferences"
    end if

end run


PS:是的,我知道我可以选择避免使用 AppleScript 并直接写入默认值,例如...

defaults write com.apple.dock tilesize -int 60
killall Dock

但是,这有一个主要缺点,它会影响应用程序徽章计数。我花了很多时间试图直接解决这个问题,现在我只是想通过 AppleScript 来推动改变,以专门避免这种情况。


真的很感谢任何帮助????????????????????????????????????????????? ?????

【问题讨论】:

    标签: applescript dock macos-monterey


    【解决方案1】:

    这在 ma​​cOS Monterey 中对我来说完全适用。

    示例 AppleScript 代码:

    tell application "System Events" to ¬
        tell dock preferences to set its dock size to 0.3
    


    注意事项:

    示例 AppleScript 代码,如上所示,在 ma​​cOS Monterey 下的 Script Editor 中进行了测试 将 系统偏好设置 中的 语言和地区 设置设置为 英语(美国)- 主要 并且为我工作没有问题 1.

    • 1 假设 系统偏好设置 > 安全和隐私 > 隐私中的必要和适当的设置已设置/根据需要解决。

    请注意,虽然在 ma​​cOS Monterey 下进行了测试,但它应该也适用于其他版本的 ma​​cOS。

    也可以在 Terminal 中作为:

    osascript -e 'tell application "System Events" to tell dock preferences to set its dock size to 0.3'
    

    或者可以在带有#!/usr/bin/osascript shebang 的shell 脚本 中使用on run argv handler。例如: p>

    示例 AppleScript 代码:

    #!/usr/bin/osascript
    
    on run argv
        set targetValue to item 1 of argv
        tell application "System Events" to tell dock preferences to set its dock size to targetValue
    end run
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-15
      • 2021-05-28
      • 1970-01-01
      • 1970-01-01
      • 2016-05-12
      • 2015-09-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多