PDA

View Full Version : Moving (and resizing?) the window of another process? (Any language.)




exscape
Oct 22, 2009, 09:39 AM
Is this possible (without too much effort)? I don't care much about the language used, as I have at least a basic understanding of all the possible candidates here. (I'm assuming Cocoa APIs will be required.)

The program should, without any GUI if possible, find the Firefox window (if there are multiple, simply exit) and resize it to a pre-defined position (and width, and possibly height). Nothing more, nothing less. No arguments, no options, except those set at compile time.

Any advice on how to do this?



robbieduncan
Oct 22, 2009, 10:55 AM
AppleScript seems like a likely candidate.

exscape
Oct 22, 2009, 10:59 AM
AppleScript seems like a likely candidate.
Thanks! :)
That tiny hint pointed me to a guide on how to accomplish exactly this. Very simple, too:

tell application "Firefox"
activate
set the bounds of the first window to {0, 0, 1440, 600}
end tell


Edit: I ramped it up a little and made it preserve the window height, too.

tell application "Firefox"
set b to the bounds of the first window
set height to (item 4 of b) - (item 2 of b)

set the bounds of the first window to {0, 0, 1440, height}
end tell

The item 4 minus item 2 is because, apparently, the list element aren't x, y, width, height as I expected, but rather the coordinates of each side of the window.

exscape
Dec 17, 2009, 06:47 AM
For some reason I don't understand, this doesn't work anymore with Firefox, which seems to report its bounds as taking up the entire screen ((0,0,1440,900) here).
Here's my new version:


tell application "System Events"
-- Set position (The menu bar will be taken care of automatically)
set position of window 1 of process "Firefox" to {0, 0}

-- Get the size, in the format {width, height}
set height to item 2 of (get size of window 1 of process "Firefox")

-- Finally, set the size
set size of window 1 of process "Firefox" to {1440, height}
end tell