I have the following code snippet:
NSNumber* windowNumber = [entry objectForKey:(id)kCGWindowNumber];
applicationName = [entry objectForKey:(id)kCGWindowOwnerName];
with this I grab the window number and the name from the window server of all Applications running.
What I want to do finally is to create a reference to whatever Window and manipulate its properties, for example if I have the window number of some instance of Safari, I would like to set it back or maximize it or maybe hide it. It is possible to do this ? some idea about how to start?
BTW I found this way of retrieve the "window number" and "application name" in an Apple Code sample Called Son of grab: http://developer.apple.com/library/mac/#samplecode/SonOfGrab/Introduction/Intro.html
if someone are curious.
Finally I accomplished this based on the apple sample Son of grab and by using the QUARTZ EVENT TAPS. This is a right way to filter events and manipulate other applications because it serves as a section 508 enabling technology.
Related
I have got a problem and I really don’t know how to solve it: I would like to change the player position of this / this video while it is opened in the background (so that another tab or application can be active at the same time). I can’t find anything helpful in the sourcecode and GUI scripting is not an option.
Thank you in advance!
EDIT: I came up with an idea: I changed the user agent to iOS 10 (iPhone) although I’m not sure if this makes the whole thing easier.
You can do this with AppleScript and JavaScript if the video player is using the HTML5 video tag. Like you said, changing your user agent to an iOS device increases your chances of being served this instead of a flash player.
First, you need to search for the correct window by URL. Then, the script will run some Javascript in the window to update the time of the video. Change the properties to fit your usage. If the page has multiple video tags, you can change the [0] to which one by order on the DOM, or target by ID instead.
property checkURL : "vimeo.com"
property changeTime : 90
try
tell application "Safari"
set theTab to first tab of window 1 whose URL contains checkURL
do JavaScript "document.getElementsByTagName('video')[0].currentTime = " & changeTime in theTab
end tell
on error
display dialog "That site is not loaded"
end try
We are trying to modify the default selected paper size for a NSPrintPanel. Using NSNotification we are able to observe and implement changes on our accessoryViews in the NSPrintPanel. However when we try to implement setPaperSize (NSPrintInfo the instance method), nothing happens and the initial paper size (default) for the default printer is selected for all other printers (We have regular printers and receipt printers).
I know the new paper size being set is correct whenever the printer changes. We are programmatically obtaining the paper sizes from the Core Print. While trying to the set the right/desired paperSize, the app doesn't break or returns any stack. So it seems, it seems apple doesn't support changes to the paper size PrintPanel.
While researching the issue, we noticed that NSPrintPanel accessory view from apple titled "Paper Handling" seems to respond to the printer changes, based on the settings you provide to Page Setup (in the file menu, NSPageLayout). So our questions are:
Is there a way to access/set the Suggested Paper size displayed in this accessoryView programmatically?
I know this accessoryView reads from page setup (NSPageLayout), thus I'd like to know if to access set these values in the "Paper Handling" accessoryView is a good approach?
Notes:
- Mac doesn't seem to allow/provide a user friendly way to set default paper sizes for each printer installed.
Accessory View we are talking about:
We have reviewed apple documentation (of course) and posting from other people with similar issues with no avail. We'd greatly appreciate a push in the right direction. Thanks in advance.
It’s been a while since I’ve done this, but what happens when you set it on the NSPrintPanel’s printInfo? Any better? It might make its own temporary copy.
I have recently been learning how to program with the Clutter GUI toolkit. One thing I haven't been able to figure out is how to set the programs title and icon for the window manager.
As illustrated in the image below, Gnome Shell says that the program name is "Unknown" and that the program does not have an icon.
So, how do I do this?
you cannot do this from Clutter: the windowing system API inside Clutter only allows basic operations.
if you want proper integration in a windowing system you should use Clutter-GTK, and embed a ClutterStage into a Gtk application.
In theory, you can do that in this way:
let stage = Clutter.Stage.get_default ();
let gdkWind = ClutterGdk.get_stage_window (stage);
// The list most containt icons in different sizes.
let list = [GdkPixbuf.Pixbuf.new_from_file("test.png")];
gdkWind.set_icon_list(list);
//The next line not work
gdkWind.set_title("This title is not added");
In practice, you only will can load the icon and the windows title, but not the task bar title for the windows. The set_title won't work as Gdk.Window reference say it will (https://people.gnome.org/~gcampagna/docs/Gdk-3.0/Gdk.Window.set_title.html). Is then a Clutter issue, because is not a GDK "special case". But well is not working.
I'm using the following piece of code to get all windows:
CFArrayRef windows = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
This gives me an array of dictionaries as found here: Front most window using CGWindowListCopyWindowInfo
Then I check their bounds to see if the mouse is in it, and the first I find is is the one my mouse is over.
Then I would like to be able to move it. I know how to use AXUIElementSetAttributeValue to move a window, though then I need a AXUIElementRef, which I can't figure out how to get out of the dictionary.
How can I solve this?
There is no way to go from a window number to an AXUIElementRef.
The closest you can get is to find the owner of the window, then ask it through Accessibility for its windows and look for one with the same title—but an app may have more than one window with the same title, so you need to figure out what you'll do in that case.
The only ways to move another application's windows are by AppleScript or by Accessibility. Using Accessibility is much more reliable than AppleScript (many, if not most, apps have incomplete and/or flaky scripting support). You can get the process ID and window title from the same window dictionary that gives the window number, but that's as specific as you can get. With AppleScript, you could only use the window's index within its application's window list, and hope that the list hasn't changed order in the split-second between you computing the index and trying to use it.
I'm using the Cocoa Accessibility API to try and modify the value of a text field (AXTextField) in another application, but I've run into a problem: my code correctly identifies and modifies the contents of the text field in question, and the text of the field visibly changes, but the changes aren't registered by the program I'm trying to control. Is there a way to do this in with the API without having to generate keyboard events?
Sample code:
AXUIElementCopyElementAtPosition(appRef,
clickPoint.x,
clickPoint.y,
&boxRef);
NSString *valueToSet = [NSString stringWithFormat:#"%f",amount];
AXUIElementSetAttributeValue(boxRef,kAXValueAttribute,valueToSet);
And the text field changes to the value specified in "amount" but the other program doesn't recognize the change - I have to go type the number in myself to get it to pick up the change (I can tell the difference, because the program responds when a new value is typed in the box). Can anyone point me in the right direction?
For posterity: Informed sources tell me that this is actually a bug in the application I'm trying to control. You can tell the difference by using UI Browser (http://prefabsoftware.com/uibrowser/) to try and set the value of the textfield; if UI Browser can't make the change stick, then the matter is out of your control.
Try telling the text field:
perform action "AXConfirm"
This is Applescript, but whatever the Cocoa equivalent is, it may make the change stick even if UI Browser can not (I've used it before).