Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window bounds set on window using AppleScript in OS X are being ignored

I am trying to create a small AppleScript to create and move some Terminal windows around my screen. The problem I am running into is that in some cases, it seems that OS X is ignoring the bounds I am setting.

Using the AppleScript Editor:

tell application "Terminal" to set the bounds of the first window to {0, 50, 600, 700}
tell application "Terminal" to get the bounds of the first window

Shows the following in the Event Log:

tell application "Terminal"
    activate
    set bounds of window 1 to {0, 50, 600, 700}
    get bounds of window 1
        --> {0, 22, 600, 672}
end tell
Result:
{0, 22, 600, 672}

Visually inspecting the window that is created when the script runs shows that Result bounds are the ones being used by the window.

Any ideas?

Edit: Running 10.6.3. My screen size is 1280 X 800. Finder reports the bounds of the desktop window to be {0, 0, 1280, 800}

like image 885
Jesse Vogt Avatar asked May 06 '10 01:05

Jesse Vogt


2 Answers

Sometimes when telling an application to set the bounds doesn't work, telling System Events to change the position and size properties does:

tell application "System Events" to tell process "Live"
    set position of window 1 to {0, 50}
    set size of window 1 to {600, 650}
end tell
like image 97
Lri Avatar answered Oct 03 '22 09:10

Lri


I hit the same problem today. Not sure what the real cause is, but the workaround is to add an extra "set position" after set bounds:

# from my window tiling script:
set the bounds of the first window to {0, 22, (screenWidth / 2), screenHeight}
set position of the first window to {0, 22}
like image 21
BobK Avatar answered Oct 03 '22 09:10

BobK