You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用AppleScript实现两个应用程序并排全屏显示?

AppleScript实现双应用并排全屏/分屏方案

macOS的分屏视图可以通过AppleScript模拟系统操作实现,以下是几种实用方案,以「日历」和「提醒事项」为例:

方案一:使用系统分屏快捷键(推荐)

利用macOS原生的分屏快捷键,快速将两个应用分别固定到左右半屏:

-- 激活日历并切换到左半分屏
tell application "Calendar"
    activate
    delay 0.5 -- 给应用激活留缓冲时间
end tell
tell application "System Events"
    keystroke "[" using {command down, control down} -- 左分屏快捷键:Control+Command+[
end tell

-- 激活提醒事项并切换到右半分屏
tell application "Reminders"
    activate
    delay 0.5
end tell
tell application "System Events"
    keystroke "]" using {command down, control down} -- 右分屏快捷键:Control+Command+]
end tell

注:该快捷键适用于支持原生分屏的应用,大部分系统自带应用和主流第三方应用都兼容。

方案二:直接设置窗口尺寸(灵活适配)

如果部分应用不支持原生分屏,可以直接通过调整窗口坐标和尺寸实现并排:

-- 获取屏幕分辨率
set screenWidth to (do shell script "system_profiler SPDisplaysDataType | grep -o 'Resolution: [0-9]* x [0-9]*' | cut -d ' ' -f 2") as integer
set screenHeight to (do shell script "system_profiler SPDisplaysDataType | grep -o 'Resolution: [0-9]* x [0-9]*' | cut -d ' ' -f 4") as integer
set menuBarHeight to 22 -- 菜单栏高度,隐藏菜单栏可改为0

-- 日历窗口占左半屏
tell application "Calendar"
    activate
    set bounds of front window to {0, menuBarHeight, screenWidth / 2, screenHeight}
end tell

-- 提醒事项窗口占右半屏
tell application "Reminders"
    activate
    set bounds of front window to {screenWidth / 2, menuBarHeight, screenWidth, screenHeight}
end tell

方案三:全屏分屏(无菜单栏/Dock)

如果需要实现真正的全屏分屏(隐藏菜单栏和Dock),可以先让第一个应用进入全屏,再触发第二个应用的分屏:

-- 日历进入全屏
tell application "Calendar"
    activate
    delay 0.5
end tell
tell application "System Events"
    keystroke "f" using {command down, control down}
    delay 1 -- 等待全屏切换完成
end tell

-- 触发提醒事项与日历并排全屏
tell application "Reminders"
    activate
    delay 0.5
end tell
tell application "System Events"
    tell process "Reminders"
        set frontWindow to front window
        -- 模拟拖动窗口到全屏边缘触发分屏
        set position of frontWindow to {0, 0}
        delay 0.3
        set position of frontWindow to {(do shell script "echo $(( $(system_profiler SPDisplaysDataType | grep -o 'Resolution: [0-9]* x [0-9]*' | cut -d ' ' -f 2) / 2 ))") as integer, 0}
    end tell
end tell

注意事项

  • 延迟时间(delay)可根据电脑性能调整,确保应用完全激活后执行操作
  • 多窗口应用需指定具体窗口(如front window表示当前前置窗口)
  • 部分第三方应用可能限制窗口操作,优先尝试方案一

内容的提问来源于stack exchange,提问作者Ricardo Brugos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 17:40:19