我试图通过使用Apple脚本来改变我的mac的规模来获得服务。
我之前找到了这个答案:
change screen resolution with AppleScript
这是我从中得到的脚本:
tell application "System Preferences"
activate
reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
end tell
tell application "System Events"
tell application process "System Preferences"
set frontmost to true
tell tab group 1 of window 1
delay 1 -- (Added a delay to the original script as it didn't always succeed)
click radio button 2 of radio group 1 -- "Scaled"
select row 2 of table 1 of scroll area 1 -- select the second row in the table to change the resolution of the monitor
end tell
end tell
end tell
但它对我不起作用。下图显示了我得到的错误以及我希望脚本选择的选项:
P.S。我也不知道如何编写苹果脚本,也不知道如何使用脚本的上下文分别命名GUI。
虽然任何有助于此服务工作的帮助将不胜感激。 :)
答案 0 :(得分:2)
这适用于我使用最新版本的Sierra
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
end tell
tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display"
click radio button "Scaled" of radio group 1 of tab group 1
click radio button 2 of radio group 1 of group 1 of tab group 1
end tell
quit application "System Preferences"
答案 1 :(得分:1)
在2018年13英寸Macbook Pro上使用Mojave,此脚本可切换两个分辨率设置:
(将德语单词更改为您的系统语言)
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
end tell
set lowResolutionSettingIndex to 2
set highResolutionSettingIndex to 3
tell application "System Events" to tell process "System Preferences" to tell window "Integriertes Retina-Display"
click radio button "Monitor" of tab group 1
click radio button "Skaliert" of radio group 1 of tab group 1
tell radio group 1 of group 2 of tab group 1
set isHighResolutionSet to get value of radio button highResolutionSettingIndex
end tell
if isHighResolutionSet then
-- Toggle native resolution
click radio button lowResolutionSettingIndex of radio group 1 of group 2 of tab group 1
else
-- Toggle Default setting - "Retina optimized"
click radio button highResolutionSettingIndex of radio group 1 of group 2 of tab group 1
end if
end tell
quit application "System Preferences"
与我在较早的答案(塞拉利昂,...)中发现的相比,我不得不更改一些内容:
(1.将窗口标题和按钮名称翻译成德语)
答案 2 :(得分:0)
displayplacer将允许您以编程方式选择显示器支持的任何分辨率/密度。这可以通过脚本执行或映射到某个热键。
例如,执行displayplacer "id:<screenId> res:1440x900 scaling:on origin:(0,0) degree:0"
将屏幕分辨率设置为屏幕截图中的红色方块。
答案 3 :(得分:0)
我将Johannes的脚本翻译成英文,并针对16英寸MacBook Pro对其进行了自定义:
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
end tell
set lowResolutionSettingIndex to 4
set highResolutionSettingIndex to 5
tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display"
click radio button "Display" of tab group 1
click radio button "Scaled" of tab group 1
tell radio group 1 of group 1 of tab group 1
set isHighResolutionSet to get value of radio button highResolutionSettingIndex
end tell
if isHighResolutionSet then
-- Toggle native resolution
click radio button lowResolutionSettingIndex of radio group 1 of group 1 of tab group 1
else
-- Toggle Default setting - "Retina optimized"
click radio button highResolutionSettingIndex of radio group 1 of group 1 of tab group 1
end if
end tell
quit application "System Preferences"