最可靠的方式是通过辅助功能api控制窗口状态:先检查并还原最小化和全屏状态,再执行axzoom动作触发全屏;对沙盒应用需先激活再降级处理,最后封装为可复用handler。

要让当前窗口自动进入全屏,最可靠的方式是模拟系统原生行为:先确保窗口处于正常状态(非最小化、非全屏),再触发全屏动作。AppleScript 本身不直接提供“全屏”命令,但可通过辅助功能 API 精准控制。
检查并还原窗口状态
全屏操作前必须处理两种常见阻塞状态:最小化和已全屏。否则脚本会静默失败。
- 读取
AXMinimized属性,若为true,设为false还原窗口 - 读取
AXFullScreen属性,若为true,执行AXZoom动作退出全屏(避免重复触发) - 建议加
delay 0.2确保状态变更生效,再进行下一步
触发全屏动作
有两种等效方式,推荐使用第一种——它更稳定,不依赖快捷键是否启用:
让智能体随处记录:支持本地 Markdown、Apple Notes、Bear、Obsidian、Notion、Evernote,可按笔记类型配置。
- 对前台窗口执行
perform action "AXZoom":这是 macOS 原生的“最大化/全屏切换”动作,对绝大多数 Cocoa 应用有效 - 或模拟快捷键
Control + Command + F:key code 3 using {control down, command down}(注意 F 键 keyCode 是 3) - 若目标应用支持菜单项,也可用
click menu item "进入全屏" of menu "显示" of menu bar item "显示" of menu bar 1
适配不同应用的兼容写法
部分应用(如 Chrome、VS Code)因沙盒限制,无法通过 System Events 直接访问窗口属性。此时需降级策略:
- 先激活目标应用:
tell application "Google Chrome" to activate - 再调用其自身 AppleScript 支持(如有);例如 Safari 支持
set current tab's URL to ...,但全屏仍需走 System Events - 若失败,可 fallback 到打开对应 URL Scheme:
open location "safari://fullscreen"(仅限少数应用支持)
封装为可复用 handler
把逻辑打包成函数,方便在不同场景调用:
on fullscreenFrontWindow()tell application "System Events"
set frontApp to first application process whose frontmost is true
set frontWindow to first window of frontApp
if value of attribute "AXMinimized" of frontWindow is true then
set value of attribute "AXMinimized" of frontWindow to false
delay 0.2
end if
if value of attribute "AXFullScreen" of frontWindow is true then
perform action "AXZoom" of frontWindow
delay 0.2
end if
perform action "AXZoom" of frontWindow
end tell
end fullscreenFrontWindow










