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

如何通过Apple Script选中Logic Pro X第二显示器上的指定应用窗口?

解决方法

报错的核心原因是脚本里的window 1默认指向当前处于激活状态的Logic窗口,主显示器的窗口UI结构和第二屏目标窗口不一致,才会触发group 2索引无效的错误。你可以先定位到第二屏的目标Logic窗口并激活,再执行后续操作即可,修改后的完整代码如下:

tell application "System Events"
	tell application process "Logic Pro X"
		-- 方法1:按屏幕位置筛选第二屏的窗口(第二屏窗口的X坐标大于主屏幕宽度,可根据自己的屏幕分辨率调整判断条件)
		set targetWin to first window whose value of attribute "AXPosition"'s item 1 > 1920 -- 此处1920替换为你的主屏幕水平分辨率
		-- 方法2:如果知道目标窗口的固定标题,直接用下面这行更稳定,替换掉上面的行即可
		-- set targetWin to window "你的目标窗口标题"
		
		-- 激活目标窗口到最前
		perform action "AXRaise" of targetWin
		set frontmost to true
		delay 0.2 -- 等待窗口激活完成
	end tell
end tell

-- 以下是你原来的操作逻辑,把所有window 1替换成targetWin即可
ignoring application responses
	tell application "System Events" to ¬
		perform action "AXPress" of ¬
			pop up button 1 of group 1 of group 2 of ¬
			targetWin of application process "Logic Pro X"
end ignoring

delay 0.1
do shell script "killall 'System Events'"
delay 0.2

tell application "System Events"
	run
	delay 0.2
	tell application process "Logic Pro X"
		perform action "AXPress" of ¬
			menu item "Enable Patch Merging" of ¬
			menu 1 of pop up button 1 of ¬
			group 1 of group 2 of targetWin
		perform action "AXPress" of ¬
			checkbox "Sends" of ¬
			group 1 of group 1 of group 2 of targetWin
		perform action "AXPress" of ¬
			checkbox "Audio Effects" of ¬
			group 1 of group 1 of group 2 of targetWin
	end tell
end tell

调试小技巧

如果你不确定目标窗口的坐标或标题,可以先运行下面的脚本打印所有Logic窗口的信息,再根据输出调整筛选条件:

tell application "System Events"
	tell application process "Logic Pro X"
		repeat with win in windows
			log "窗口标题:" & name of win
			log "窗口左上角坐标:" & value of attribute "AXPosition" of win
		end repeat
	end tell
end tell

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 04:48:03