Finding out if a Window is Resizable - objective-c

Is there a way to determine whether the active window (not of my process, but a different application) is resizable?
Edit: I would prefer to do this without applescript as it then depends on the application being scriptable.

Use Accessibility. Once you find the window you want to examine, test whether it has the kAXGrowAreaAttribute attribute (the value for which would be the grow area itself, a.k.a. the “size box” or [the Windows term] “resize handle”). A window that has one is resizable; a window that doesn't have one is not resizable.
The user will need to have access for assistive devices turned on, but making that happen is easier than scripting unscriptable applications.
Edit from the year 2011: Lion killed off size boxes, so now you'll need to test whether the window's size attribute can be changed.

Yes, you can check if the "frontmost window" of the target application is resizable! You can perform the scripting request via applescript, scripting bridge or a third party framework!
However, in any case, it's needed that the target application is scriptable and you can access to the "resizable" property (of the "frontmost window" object) via a scripting request!

Depends on how you're getting access to the window. There's a property in AppleScript on Window objects, resizable, that indicates this.

Related

In Objective-C, When monitoring other apps windows using accessibility APIs, is there a way to know if a window was moved pressing the command key?

I am writing a Cocoa Objective-C application for the macOS, and I am using this very good answer here to be notified of window position changes in other applications. Within my app, I can use the event returned by [NSApp currentEvent] to determine the key modifiers. How can I ascertain the same for another app that I am monitoring ? To be simple, I would like to know if a window of an application was moved or resized while pressing the command (or option) key. Many thanks for any help.

Programmatically open NSWindow in another Desktop (Space)

In my OSX Project I want to:
identify the Desktop (one of the expose Spaces) where a NSWindow resides;
open a NSWindow in a determined Space, not only on current Space.
Is there a way to do these simple tasks?
Exploring the documentation (NSWindowController, NSWindow, NSScreen) I can't find anything regarding multiple Desktop Management.
Thanks in advance!
You'd think there would be some API for working with Spaces, but there really isn't. You can use CGWindowListCopyWindowInfo to determine which Space a particular window is on, but there's no easy way to open a particular window on a specific space.
There is private API to move windows between spaces, of course. Whether you want to use this in your application depends on your needs - you couldn't use it on a Mac App Store application, obviously.
Found a copy-of-a-copy of the reverse-engineered header I was looking for:
https://gist.github.com/rjw57/5495406

How to emulate mouse clicking/mouse moving/key typing in the global context?

Emulate means to invoke these events programatically.
Global context means that these event invocations should affect the whole desktop (sort of global environment) rather than the application which produces them. Moreover, the application itself should have no windows - it has to simply execute in background and produce these events due to some logic. In other words, if, for example, this application puts mouse in "global" arbitrary position and invokes a double click event and there is an icon of some other application under the cursor then this "other" application should start.
Which library can I use to achieve it?
Note: I don't specify OS since I hope that the library is supposed to do it in a cross-platform way. If that's not possible then I will be fine with the Windows only solution.
I found out that Java's java.awt.Robot has all requested features.

Get live screenshot of window in objective-c

I'm trying to find a way to get a live view of a specific window. In the same way that Mission Control and Exposé will show you live views of windows that are currently obscured by other windows (this is also done by Hyperdock, so I'm pretty certain that its not a private API).
What is the functionality called? And so where is the documentation on it?
You want the Quartz Window Services API. Basically, you want to create a window list with the windows you're interested in and use CGWindowListCreateImage to get a picture of the window's contents.

Locking a screen in 10.6

How would I go about locking a screen like Keychain does, meaning preventing all access to Dock, menubar, desktop, etc. Basically just a black screen that I can add a password field to, for the user to return to the desktop? I am well aware of the Carbon method, but I want the NSApplication method because this is an all Cocoa application.
Thanks~
If you can get away with not writing this code yourself, all for the better. It is usually a terrible idea to write your own code to lock the screen, considering the number of vulnerabilities that have been found in screen locking code over the years. If you have a Carbon call that can do it, go ahead and use that... don't worry about the "purity" of your Cocoa code.
However, if you decide to write this yourself, here's what you do:
First, capture all the screens using CoreGraphics. See: http://developer.apple.com/mac/library/documentation/GraphicsImaging/Conceptual/QuartzDisplayServicesConceptual/Articles/DisplayCapture.html
Next, create a new NSWindow and put it in front of the window that's used for capturing the screens. You'll have to call a CG function to get the "order" of the black window covering each screen, and order the new window in front of that. Normally, the black window has an order so far forward that everything is behind it. Put a password field in the window. Do NOT use an ordinary text field or write your own code for password input. The password input field has a ton of special code in it so you can't copy text out of it, and other programs can't listen to keystrokes while you're typing into a password field. So use the one that Apple provides.
Last, put the computer in "kiosk mode". This mode allows you to disable alt-tab, user switching, the menubar and dock, and even the ability to force quit. See: http://developer.apple.com/mac/library/technotes/KioskMode/Introduction/Introduction.html
It's not a lot of code, it just uses a few different APIs so you'll spend most of your time bouncing between API docs. I suggest writing the screen lock code as its own application (just add a new application target to your Xcode project) and then put the screen locker inside your application bundle. This used to be (as of 10.4) how Apple Remote Desktop implemented the "Lock Screen" functionality, but I can't find the app anymore.
I believe the Cocoa replacement to the SetSystemUIMode API was not introduced until 10.6.
If you can live with Snow-Leopard-only code, the answer is - setPresentationOptions: on NSApplication.