Applescript - 在 MacOS Monterey 上设置系统偏好设置底座大小滑块的值

     2023-02-16     41

关键词:

【中文标题】Applescript - 在 MacOS Monterey 上设置系统偏好设置底座大小滑块的值【英文标题】:Applescript - Set value of System Preferences dock size slider on 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 来推动改变,以专门避免这种情况。


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

【问题讨论】:

【参考方案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 shebangshell 脚本 中使用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

【讨论】:

Applescript - 在 MacOS Monterey 上设置系统偏好设置底座大小滑块的值

】Applescript-在MacOSMonterey上设置系统偏好设置底座大小滑块的值【英文标题】:Applescript-SetvalueofSystemPreferencesdocksizeslideronMacOSMonterey【发布时间】:2022-01-1811:50:35【问题描述】:我正在尝试使用AppleScript将扩展坞大小更改为指定值... 查看详情

applescript快速入门(代码片段)

AppleScript快速入门AppleScript顾名思义是苹果开发的一套脚本语言,利用AppleScript在macOS系统上可以对其他程序进行操作,点击按钮、发送消息、模拟自动化执行功能,比如可以打开浏览器,清空回收站等等一些操作,是一个非常有... 查看详情

OS X (macOS) 和低级 C(Objective-C 替代方案)中的 Applescript

】OSX(macOS)和低级C(Objective-C替代方案)中的Applescript【英文标题】:ApplescriptinOSX(macOS)andlowlevelC(Objective-Calternative【发布时间】:2016-08-1816:28:51【问题描述】:您好,我知道我可以使用Applescript之类的工具来控制操作系统的不同方... 查看详情

text[formatierkontakte]fügt+49vorjedetelefonnummer#macos#applescript(代码片段)

查看详情

macos-代码调用terminal执行脚本或者杀死进程窗口

...类似,属于不正常关闭。3,关闭Terminal当前第一个窗口该AppleScript执行时会触发Terminal提示如果想要不弹出提示框的执行下面AppleScript直接执行会报错,原因在于这种操作属于隐私权限,osascript本身不允许发送按键操作。除非你在... 查看详情

测试开发-怎么能忘记打卡呢-神器applescript(代码片段)

...继续给大家介绍一款我自认为比较好用的东西,MacOS下的AppleScript,AppleScript像是mac电脑给开发者留下的一个入口一样,他不同于其他语言那么复杂,可以让我们使用很多MacOS提供的诸多方法也是mac上操作应用程序为数不多的途径... 查看详情

Xcode 13 AppleScript 框架无法将 UI 连接到 Applescript 代码

】Xcode13AppleScript框架无法将UI连接到Applescript代码【英文标题】:Xcode13AppleScriptframeworkcan\'tconnectUItoApplescriptcode【发布时间】:2021-11-2512:32:22【问题描述】:尝试使用带有AppleScript框架的Xcode13为MacOS11.5创建AppleScript可执行文件。开... 查看详情

在 macOS Catalina 下的 Finder 中查找活动壁纸文件的脚本

...布时间】:2020-02-1919:52:59【问题描述】:我曾经使用两个AppleScript脚本从macOSMojave下的桌面1和桌面2(双显示器模式)中找出实际壁纸图像的文件名。一个脚本用于主监视器,另一个脚本用于第二个监视器。在 查看详情

在后台显示和更新 applescript 输出

】在后台显示和更新applescript输出【英文标题】:Displayandupdateapplescriptoutputinbackground【发布时间】:2015-03-2205:03:02【问题描述】:我有一个简短而可爱的程序,可以在applescript中输出我的内部和外部ip。这里是Applescript代码:setinIP... 查看详情

如何在 Applescript 中调用 Automator 变量?

】如何在Applescript中调用Automator变量?【英文标题】:HowtocallAutomatorvariableinApplescript?【发布时间】:2014-02-1822:37:22【问题描述】:所以我有一个Applescript,它显示一个对话框,然后自动设置一个变量作为条目例子。..输入“AAAAAAA... 查看详情

Applescript 在 Photoshop 中隐藏提示

】Applescript在Photoshop中隐藏提示【英文标题】:Applescripthidepromptsinphotoshop【发布时间】:2014-06-2412:45:24【问题描述】:任何人都知道是否有隐藏applescript中提示的命令。我知道您在Illustrator中使用以下内容:tellapplication"AdobeIllustrat... 查看详情

applescript:如何在多个窗口中执行击键

】applescript:如何在多个窗口中执行击键【英文标题】:applescript:howtoexecutekeystrokeinseveralwindows【发布时间】:2021-08-1813:48:21【问题描述】:我需要在某些应用程序(例如,safari浏览器)中通过applescript执行一些击键(例如,cmd+t... 查看详情

Applescript 在 iTunes 中超时

】Applescript在iTunes中超时【英文标题】:ApplescripttimedoutiniTunes【发布时间】:2012-10-0605:00:40【问题描述】:我写了一个简单的applescript来自动将文件添加到iTunes中并填充元数据。当我直接从编辑器运行它时,它可以工作,但从iTune... 查看详情

如何在 AppleScript 中操作“数据”对象

】如何在AppleScript中操作“数据”对象【英文标题】:Howtomanipulate"data"objectsinAppleScript【发布时间】:2015-02-2006:10:57【问题描述】:我正在通过AppleScript使用iTunes。轨道的artwork元素包含图像data(或rawdata,在实践中返回相... 查看详情

使用 Applescript 在 Xcode 中选择文件

】使用Applescript在Xcode中选择文件【英文标题】:SelectingafileinXcodeusingApplescript【发布时间】:2014-05-1514:44:50【问题描述】:我想打开一个Xcode项目并使用applescript在项目导航器中选择Xcode项目(.xcodeproj)。我为Finder尝试了以下代码sn-p... 查看详情

使用 JavaScript 语法在 AppleScript 中打开 XML 文件

】使用JavaScript语法在AppleScript中打开XML文件【英文标题】:OpenXMLfileinAppleScriptwithJavaScriptsyntax【发布时间】:2021-11-0701:22:19【问题描述】:我正在编写我的第一个更大的AppleScript,并且由于我通常开发TypeScript,我决定使用AppleScrip... 查看详情

如何使用 AppleScript 在 iMessage 中开始新对话?

】如何使用AppleScript在iMessage中开始新对话?【英文标题】:HowtostartnewconversationiniMessageusingAppleScript?【发布时间】:2016-12-2522:53:07【问题描述】:所以我正在创建一个基本上可以自动发送信息的applescript。我现在的工作是:onrunmsg... 查看详情

如何使用 AppleScript 在 iMessage 中开始新对话?

】如何使用AppleScript在iMessage中开始新对话?【英文标题】:HowtostartnewconversationiniMessageusingAppleScript?【发布时间】:2016-12-2522:53:07【问题描述】:所以我正在创建一个基本上可以自动发送信息的applescript。我现在的工作是:onrunmsg... 查看详情