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

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

Related

Recording X windows events

I am a novice when it comes to X windows but have some knowledge of Unix as such.
My project requires me to track user input and output on X window system. For instance, if the GUI is used to configure a route, I would like to know what application is used and what route has been configured. So far, I have explored the following options with partial success.
1)Tried to hook functions like XDrawString and XDrawText using LD_PRELOAD.
2)Used xwininfo to obtain window id and tools like xev.
3)Looked through similar discussions in this forum especially on xev and xinput
1)May not work with if X11 is statically linked? Not sure.
2)xev does not record key press events for a file edited with gedit or attempting to rename a file from the GUI
3)I am trying to go through X windows system internals.
I am pretty discouraged so far. Any input/pointer will be appreciated.
I think you want the cnee program from the Xnee project, which uses the X window system Record extension. The examples that I see for cnee are almost always about recording input events, but, according to the Xnee manual at https://xnee.files.wordpress.com/2012/10/xnee1.pdf, section 3.2.1 ("Record"), "Xnee can record the whole X11 protocol, not just mouse and keyboard events."
Regarding font operations, I believe that X font facilities, mostly through the X font server, evolved over time too, so it might be the case that the applications that you care about are doing X font operations which you can trace.

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.

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

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

How to implement "Open With" contextual menu in OS X

Apps in OS X that can open files to launch their respective applications often let the user choose the app that'll open the file. An example is the Finder.
I am still unclear about what's the best solution to implement this. The challenges are performance and showing the app's icon.
First, to get the list of apps, I found only LSCopyApplicationURLsForURL().
The major difficulty for me now is to get the app icons. All I have is the URLs (paths) to the apps. The only way I know of to get the icons would be to create a CFBundle object and then read the app's plist to get the icon data. But that appears to invole lots of disk access, and I could imagine it'll be quite inefficient if the app is located on a remote file server.
I believe that there's also a cached database about the apps, which includes icons and display names (without extension), and such. But where is the API for that?
Note: The app is Carbon based, but I can make use of Cocoa (NS...) functions if necessary. Also, Support for 10.5, even 10.4, would be appreciated.
Alright. I solved it eventually.
I now use the Carbon function GetIconRefFromFileInfo(), which still works in Lion, though it's marked deprecated/obsolete.
I had also tried to use QLThumbnailImageCreate(), but that didn't get me any results, oddly. No idea what I did wrong.
For Cocoa apps, [[NSWorkspace sharedWorkspace] iconForFile:path] can be used (thanks to C. Grunenberg of DevonTechnologies for this tip, where it's used with EasyFind).

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.

Resources