要通过边界将应用程序从当前监视器移动,可以使用以下AppleScript代码示例:
tell application "System Events"
set appProcess to first process where frontmost is true
set appWindow to first window of appProcess
set appBounds to bounds of appWindow
-- 获取当前监视器的大小和位置
set monitorBounds to bounds of window 1 of application "Finder"
-- 设置应用程序新的位置
set newX to (item 3 of monitorBounds) + 20 -- 相对于左侧边界的新X坐标
set newY to (item 4 of monitorBounds) + 20 -- 相对于顶部边界的新Y坐标
set newBounds to {newX, newY, (newX + (item 3 of appBounds)), (newY + (item 4 of appBounds))}
set bounds of appWindow to newBounds
end tell
这段代码首先通过System Events
应用程序获取当前处于活动状态的应用程序的进程和窗口。然后,它获取应用程序窗口的边界(位置和大小)以及当前监视器的边界。最后,代码计算出新的应用程序窗口位置(相对于当前监视器的左上角)并将其应用于应用程序窗口。
请注意,此代码示例假定前景应用程序具有一个窗口。如果前景应用程序没有窗口,或者有多个窗口,那么需要根据需要进行修改代码。