views:

367

answers:

1

How to resize a window of any application programmatically with objective-c / cocoa? So far I've got the app name and the window number but don't know how to access the window.

I could do it with AppleScript but want to learn it with objective c.

AppleScript example:

tell application "System Events"
    set frontApp to name of first application process whose frontmost is true
end tell


tell application frontApp
 set bounds of window 1 to {(screenWidth / 2), 0, screenWidth, screenHeight}
end tell

Thanks for any advice.

+1  A: 

In this case, AppleScript really is the right tool for the job. Telling another application to resize it's window in is an automation problem. Writing that code "in Cocoa" would just mean more work building/sending AppleEvents from a lower level.

I would try using NSAppleScript to load and execute that script you have from within a Cocoa program. If you learn how to do that, you'll know how to embed AppleScript in your Objective-C programs, and that's a handy trick to have in your utility belt.

Good luck!

Vincent Gable