【发布时间】:2022-01-18 11:50:35
【问题描述】:
我正在尝试使用 AppleScript 将扩展坞大小更改为指定值。我的操作系统是 MacOS Monterey v12.0,这可能很重要。
我能够掌握适当的“Dock Size”滑块,但我不知道如何直接设置它的值。
鉴于我在 tell slider 块中,我已经尝试过......
set value to targetValueset 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