今あるモニターの中央にウインドウを移動する [AppleScript辞書はつくれるか?]
(* 今あるモニターの中央にウインドウ(theWindow)を移動 *) set theScreen to current application's class "NSScreen"'s screens() --マルチモニターの位置情報を取得 set {{windowX, windowY}, {windowW, windowH}} to theWindow's frame() --ウインドウの位置情報を取得 set {windowCenterX,winsowCenterY} to {windowX + (windowW / 2) + 0.1, windowY + (windowH / 2) + 0.1} --0.1の意味は中心位置が境界線だったっ場合の回避用 set targetMonitor to 0 repeat with screenNo from 1 to (count of theScreen) set {{screenX1, screenY1}, {screenWidth, screenHeight}} to (item screenNo of theScreen)'s frame() set {screenX2, screenY2} to {screenX1 + screenWidth, screenY1 + screenHeight} if (windowCenterX > screenX1) and (windowCenterX < screenX2) and (winsowCenterY > screenY1) and (winsowCenterY < screenY2) then log "---------" set targetMonitor to screenNo set originX to screenX1 + (screenWidth / 2) -(windowW / 2) set originY to screenY1 + (screenHeight / 2) -(windowH / 2) theWindow's setFrameOrigin_(current application's NSMakePoint(originX,originY)) exit repeat end if end repeat if targetMonitor = 0 then return false |
コメント 0