Retrieve and modify the value of an interface element in another Mac OS application - macos

On Mac OS, I've seen a few application that manage to control the user interface elements of other applications in order to provide a new way to control them (via a track pad, for example).
Can anyone please tell me how that's done?

Some obvious (and non-hackish) ways to achieve that would include
Accessibility, or
Apple Script

Related

Mac OSX daemon for a task to maximize windows

I want a small functionality for all my Mac OSX application windows. When I double click on the title bar, either nothing happens or the application will get minimised(if the appropriate option is checked) instead, I want to create a functionality where it will get maximised completely(not full screen).
I am assuming that I should write a daemon for this but I am quite new to coding.
So my question is:
Can my "goal" be achieved by a daemon?
No, it cannot. There is no way to implement this functionality with public APIs on Mac OS X.

OSX Carbon: Quartz event taps to get keyboard input

I want to get Keyboard Input on OSX using c++ without using Cocoa, deprecated Carbon UPP handlers and if possible without using IOHID since that's alot of extra work.
I allready implemented a simple mouse class using quartz event taps and it works like a charm and now I'd like to use them to implement a keyboard class. Anyways as the reference states under CGEventTapCreate:
http://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html
you can only access key events if one of the following is true:
The current process is running as the root user.
Access for assistive devices is enabled. In Mac OS X v10.4, you can
enable this feature using System Preferences, Universal Access
panel, Keyboard view.
that is a very serious limitation since I also want my application to work without any weird settings. Is there any way to work around this? If not, is there any alternative to using Taps in Carbon?
Thanks!
The easiest way is to use the semi-deprecated Carbon function RegisterEventHotKey, see this SO Q&A, for example.
If not, you need to live with that restriction. The restriction is there to prevent a bad person to install keylogger behind the scenes. You need to ask the user to open the preferences, type the admin password etc.
You could try to use AXMakeProcessTrusted. This is supposed to be the same as Access for assistive devices on a per process basis.

How to get a list of all open NSWindow from all running application?

Is there a way to get list of open or visible NSWindow from mac desktop?
Note that not all windows are necessarily NSWindows, and that NSWindow only provides an interface to windows in your own address space.
The supported way to access every window is the CGWindow API. Take a look at the Son of Grab sample code to see how it's done.
You can use the accessibility API (accessibility must be enabled under System Preferences for it to work) to get information on windows (and other UI elements) from other processes. This question might be just what you're looking for.
ALL running applications? No. You can only get the NSWindows of your own app. You may be able to use Universal Access or Core Graphics APIs to get some information about windows of other apps, but not full access.

Creating a Mac OS application that interacts with all text fields

What would be the first step to creating an application for Mac OS X that would take user interaction from any text field in the system? A couple examples of apps that do this are TextExpander and Typinator.
What I want to do would be using similar functions to access Text fields throughout the computer during user input to give other additional options, I'm just not sure where to even start in Xcode and with what type of project to use.
Any help or links would be greatly appreciated! Thanks!
I think you can probably capture what's being entered into text fields using an Input Manager, although these may be deprecated as of OS X 10.6. You might also want to look at SIMBL.

How to detect which Space the user is on in Mac OS X Leopard?

Mac OS X Leopard has a virtual desktop implementation called Spaces. I want to programatically detect which space the user is currently on.
Cocoa is preferable but AppleScript is acceptable if there's no other way.
I've seen a couple of AppleScript implementations, but the techniques they used seemed a bit too hacky to use in production code (one relied on causing an error and then parsing the error message to get the current space, the other interrogated the Spaces menu GUI)
Use HIWindowGetCGWindowID to get the CGWindowID for your WindowRef.
Use that ID with CGWindowListCreateDescriptionFromArray from CGWindow.h to get information on your window.
Look at the returned dictionary and extract the (optional) kCGWindowWorkspace key. That is your space ID for your window.
If anyone still cares, I've put together a little commandline util based on the answers here which you can get at http://github.com/shabble/osx-space-id

Resources