如何通过AppleScript将macOS版Safari默认页面缩放设为100%
macOS端AppleScript自动设置Safari默认页面缩放为100%
以下脚本可直接在macOS上运行,自动完成对应配置,无需逐层手动点击菜单:打开Safari设置→进入网站标签→找到页面缩放项→将「访问其他网站时」的默认缩放值选为100%。
可直接运行的脚本代码
-- 唤起Safari浏览器 tell application "Safari" to activate delay 0.5 tell application "System Events" tell process "Safari" -- 兼容新旧macOS版本的设置/偏好设置菜单命名 try click menu item "设置…" of menu "Safari" of menu bar 1 on error click menu item "偏好设置…" of menu "Safari" of menu bar 1 end try delay 1 -- 切换到网站设置标签 click button "网站" of toolbar 1 of window 1 delay 0.5 -- 侧边栏选中页面缩放选项 select (first row of outline 1 of scroll area 1 of splitter group 1 of window 1 whose value of static text 1 is "页面缩放") delay 0.5 -- 下拉选择100%默认缩放 click pop up button "访问其他网站时:" of group 2 of splitter group 1 of window 1 delay 0.3 click menu item "100%" of menu 1 of pop up button "访问其他网站时:" of group 2 of splitter group 1 of window 1 delay 0.3 -- 关闭设置窗口 click button 1 of window 1 end tell end tell
使用说明
- 首次运行前需要给运行脚本的载体(脚本编辑器/终端/快捷指令等)开启辅助功能权限,打开系统设置→隐私与安全性→辅助功能,勾选对应应用即可,否则系统会拦截脚本的模拟点击操作
- 运行时不要最小化Safari窗口,尽量保持窗口在前台,避免窗口层级异常导致脚本点击错位
- 如果你的系统语言为英文,将脚本中对应的中文控件文本替换为英文即可:
设置…换为Settings…、偏好设置…换为Preferences…、网站换为Websites、页面缩放换为Page Zoom、访问其他网站时:换为When visiting other websites: - 脚本适配macOS 12及以上版本,低版本系统如果出现控件定位偏差,可以适当调整delay延迟时长适配机器运行速度
内容的提问来源于stack exchange,提问作者Ritesh kumar
相关产品推荐
相关产品推荐

