Home > Blockchain >  how to calculate the position from right side of the screen so that the entire window is always show
how to calculate the position from right side of the screen so that the entire window is always show

Time:11-22

I am currently using Applescript to calculate the size and position of a window from left to right which works great. Here is an example where I am trying to position of a window as "Left half of the screen"

tell application "System Events"
    tell application process "Xcode"
        activate
        tell window 1 to set size to {(1600) / 2, 814}
        tell window 1 to set position to {0, 0}
    end tell
end tell

I am trying to work on positioning of the window "Right half of the screen" (technically I can calculate this by setting the X = screenWidth/2 but the issue is, the window of Xcode app some part of the screen is not visible the user where as if I calculate it from right I can ensure the entire window is on the screen visible to the user.

Actual result: https://share.cleanshot.com/COYgKD

Expected result: https://share.cleanshot.com/BIELCA

Goal: Show right half of the window that ensure the entire window is on the screen visible to the user

Any help is appreciated

CodePudding user response:

To obtain your your screen's dimensions:

tell application id "com.apple.finder" to set ¬
        [null, null, screenW, screenH] to the ¬
        bounds of the desktop's window

XCode is scriptable, I believe, so there's no need to invoke System Events to get or set its size and position. However, scriptable application windows offer this by way of the bounds property just like the desktop's window above:

tell application id "com.apple.Xcode" to tell ¬
    window 1 to tell (a reference to its bounds)
    set [X, Y, W, H] to its contents
    set |           
  • Related