Get the list of windows for running application on Mac - objective-c

I used samples from CGWindow API and SonOfGrab samples to get the windows list and grab them, in particularly I used CGWindowListCopyWindowInfo for retrieving the list of windows along with CGWindowListOption specified. However I have a problem here. The thing is that I only want to see the list of windows which belong to a running applications, i.e. I don't want to get windows for dock, system menu etc.
I tried to set kCGWindowListExcludeDesktopElements and kCGWindowListOptionOnScreenOnly flags, they removed some windows I'm not interested in, however even with these options set, I still have 'Dropbox icon in menu bar' window, dock window, system panel window etc. Is there a way to filter them out?
I also tried to request [[NSWorkspace sharedWorkspace] runningApps] to get the list of running applications. My idea was to get the process identifiers from runningApps and remove from the list of windows those ones who don't have process identifiers from the runningApps list. Unfortunately it didn't work out, since the list of running applications is way bigger than I expected and it also contains dashboard applications and other things. I tried to find a property or something like this to distinguish between these 'system apps' and 'real apps', however I wasn't able to achieve this.
Does anyone know how to solve this?
Thanks.

you could:
get the bundle for a running application
check its plist for if it is has a UIElement key -> those wouldn't be in the dock
=> then filter the windows against the remaining PIDs

Related

App modeller, Identify button not showing up in blueprism spying

I am creating calculator VBO in blueprism object studio.
In application modeller I gave calc.exe path and able to launch calculator, but I am not getting identify option to spy on any element..
In Element, After clicking Launch buttion, identify is appearing for a split of sec and Launch button is coming back instead of Identify
PS- As mentioned in videos and links, I have launched calc via application modeller not directly via windows..
I am using windows 10, BluePrism V.5.0.11.0 versionenter image description here
Windows 10 calculator is complicated case, please consider using different application in your training. For example paint is much simpler to get started.
If you really need to get that going, then you may need to launch application first, using one object, and afterwards use second object to attach and interact with it.
can be two reasons
1. Either your application is not launched properly.
2. Sometimes we face problems with some versions of applications.
The best way to fix your problem is
Edit your settings remove the application path from the navigate stage.
Launch the application separately
Open Navigate stage > Action > Attach
Provide the window title within quotes (example: "Calculator")
Click OK then run the object
Now if you go to application modeller
You will be able to see the identify button under the element.
Hope this will help you.
I resolved this by unchecking "Disable invasive techniques (hooking)".
The Windows 10 calculator runs with process name win32calc which is also located under c:\windows\system32.
So when you launch the application please make you identify the applications process name and its location
I resolved this by circumventing to windows 7 calculator instead of a windows 10 calculator on windows 10.
Link to download win 7 calculator for win 10-
https://winaero.com/download.php?view.1795
This will be installed in the same place as your default calculator.
Inside-
C:\Windows\System32
The name of the app in my case was "calc1.exe" to avoid collisions with the default calculator.
I used this as my base reference app for spying and it worked.
Also note, the hover to highlight button seems to be a bit buggy, try a bit hit and trail to get you required button to be highlighted and mark using "Ctrl+LeftClick"

Get list of opened windows and minimised windows

I'm using CGWindowListCopyWindowInfo to obtain list of windows opened in OSX system. I would like to get all opened windows + minimised window (windows which appears in the bottom of the dock). I've already tried all possible options of this function (https://developer.apple.com/reference/coregraphics/1666230-quartz_window_services/1805250-window_list_option_constants?language=objc)
Using it with option kCGWindowListOptionOnScreenOnly returns obviously proper list but without minimised windows. Without it, I get minimised but also all different windows which are not minimised (e.g. splash screens of other applications).
Second attempt was to use properties of window returned by CGWindowListCreateDescriptionFromArray(https://developer.apple.com/reference/coregraphics/1455215-cgwindowlistcreatedescriptionfro?language=objc) but I didn't find the way also.
Thanks.
Update:
Also using accessibility API isn't a solution here since the user has to explicitly allow particular application to control the computer in system preferences.

Register Double-Click on Desktop (but not on Icons !)

Here's a though question:
I need to find out when the user double-clicked the OS X desktop, but not icons on it.
Now, I have thought of the following solutions, though I am not sure if they are doable:
Using desktop icons position (not sure how to get them), and the size of the desktop icons, we could theoretically check once the user double-clicks on the desktop, if it is inside one of the icon areas. Contra: Might not be flawless as some icons might be transparent or not taking up the entire icon size.
Maybe there is a variable that tells us if a icon from the desktop has been clicked? Then we could just check if that variable has been activated when the user double-clicked the last time the desk.
I am certainly still open to other (better) solutions, but they need to be sandboxable for the Mac App Store.
This is probably not going to be appropriate for the Mac App Store, for a number of reasons.
First, how are you going to intercept clicks outside your window? There are a few different mechanisms for this (e.g., event taps), but none of them are allowed in sandboxed apps. And that's intentional, and for a good reason—you're not supposed to be interfering with other apps or with the OS.
On top of that, it's hard to imagine that whatever you're trying to do wouldn't count as non-standard UI/HIG stuff, which is another reason for rejection.
But, assuming none of that were a problem, and you could intercept clicks on the desktop, there's no documented way to get all the icons on the desktop, so you have to read the .DS_store file directly, which means relying on private implementation information, which is another thing you're not allowed to do.
Finally, you have to get access to that .DS_store file. Unless you're expecting the user to drag the (invisible) file or its parent directory to your app or select it in an NSOpenPanel or something, the only way to get such access from inside the sandbox is via a temporary exception entitlement. Which you can't use unless you can justify to the reviewer why you need it as a workaround for a bug or limitation in the OS. So, what's your justification going to be?

Mac OS X: Global Shortcut to get selected text/image in Application

I'm trying to build an app that get's selected text from other applications if a certain shortcut/hotkey is pressed. First I tried the Carbon Hotkey API, but then I couldn't get selected text from other applications. Second I've tried building a service that gets the selected text from other applications and is called with a global shortcut, but I wasn't able to use a custom shortcut. Somehow only CMD+SHIFT is allowed as a modifier in the plist and these kind of shortcut is already used in many applications so it's often not working. CTRL and a key would be a cool shortcut, because not many applications use this kind of shortcut, but I can't specify such a modifier.
Any Ideas how to solve this problem?
To answer your second question, you can manually edit the Services plist file. Find details here:
Set Custom KeyEquivalent in Services Menu

Getting process list and hiding a specific app

How do I get a process list (in a popup button), and then when the user selects the application, can I hide/kill/minimize/quit the application?
-[NSWorkspace runningApplications] will give you an NSArray of NSRunningApplication instances representing currently-running processes. I'm not exactly sure what causes a program to be excluded from that list, but it does include any application that the user has launched from the Finder. It also includes a couple of things (the Finder itself, and the loginwindow process) that you don't want to mess with, as well as faceless applications.
You can filter those out using filteredArrayWithPredicate:; the objects you want to keep have an activationPolicy of NSApplicationActivationPolicyRegular.
Once the array is filtered, you can search it, using bundleIdentifier, bundleURL, or localizedName to find the app you want. Then send hide or terminate as you like to that NSRunningApplication instance.
Apple has a sample project that demos all this, called AppList.