Setting a process' window to front. Why isn't this working when maximized? - objective-c

I'm trying to get an app's window (let's say Firefox as an example) and bring it to the very front and focus it. It works fine when the program isn't maximized, allowing me to bring any of Firefox's windows to the front.
However when maximized, it just brings the whole group of windows to the front, regardless of whether or not it was the window I specifically chose. Here's what I'm using:
AXUIElementPerformAction (element, kAXRaiseAction);
ProcessSerialNumber psn = [self serialNumberOfPid: [appPid unsignedIntValue]];
SetFrontProcessWithOptions (&psn, kSetFrontProcessFrontWindowOnly);
Reading some other posts, I've tried this:
AXUIElementSetAttributeValue(element, kAXMainAttribute, kCFBooleanTrue);
AXUIElementSetAttributeValue(element, kAXFocusedAttribute, kCFBooleanTrue);
AXUIElementPerformAction (element, kAXRaiseAction);
ProcessSerialNumber psn = [self serialNumberOfPid: [appPid unsignedIntValue]];
SetFrontProcessWithOptions (&psn, kSetFrontProcessFrontWindowOnly);
What am I doing wrong? Why does it only happen when the windows are maximized? Is there a better way of doing this?

Try using the kAXFrontmostAttribute property:
AXUIElementSetAttributeValue(element, kAXFrontmostAttribute, kCFBooleanTrue);

Related

PyDub opens window no matter what I have tried

I'm trying to make a music making program and used PyDub for playing sounds as I could change the pitch. However, it opens a window whenever playing a sound. No matter what I do, it will open a window.
I have tried using
startupinfo = subprocess.STARTUPINFO
startupinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess._subprocess.SW_HIDE
behind every
p = subprocess.Popen(conversion_command, stdin=devnull, stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=startupinfo)
but to no avail. I have also tried putting creationflags=0x08000000 in the
p = subprocess.Popen(conversion_command, stdin=devnull, stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=startupinfo)
which also does not work.
Edit: I found another post which set default creationflags to 0x08000000, which worked!

Setting currentTime to anything sets time back to 0 in videojs

I'm doing something fairly simple with videojs. I simply want to set the time to an arbitrary point on the timeline by clicking on an externally build UI (not the default seek stuff, but a set of divs that are acting like a progress bar.)
All the documentation and every post seems to indicate that setting currentTime as in object.currentTime(time) works. But in my case it doesn't. Not in the console, not anywhere.
Here's my code:
function clearSetTimeBug(videoObj,timeToSetTo){
console.log('timeToSetTo:'+timeToSetTo);
console.log("-1."+videoObj.id()+" readyState(): "+videoObj.readyState());//returns 4 (loaded)
console.log("0."+videoObj.id()+" bufferedEnd(): "+videoObj.bufferedEnd());//returns about 2 seconds ahead of where the playhead is)
if(videoObj.bufferedEnd()>timeToSetTo){
console.log("1."+videoObj.id()+" currentTime(): "+videoObj.currentTime()); // returns a valid videojs object id and then shows the currentTime to be where the video's current timecode as a float.
videoObj.currentTime(timeToSetTo);//this should totally work!
console.log("2."+videoObj.id()+" currentTime(): "+videoObj.currentTime());// shows that the current time is 0!
}else{
//I added this to just go to as far as it's buffered, but this doesn't work either
console.log("3."+videoObj.id()+" currentTime(): "+videoObj.currentTime());
console.log("4. newTime: "+videoObj.bufferedEnd());
videoObj.currentTime(videoObj.bufferedEnd());
pageTime=videoObj.bufferedEnd();
console.log("5."+videoObj.id()+": "+videoObj.currentTime());// still shows that the current time is 0!
console.log("6. pageTime:"+pageTime);
}
}
The player is spun up like this:
function setUpPlayers(playerId,playlist,local_file,index){
let myAspectRatio=heightRatio+":1"
let videoTag="";
videoTag +="<video id='playerInstance"+index+"' class='video-js vjs-fluid' width='100%' height='100%'>\n";
videoTag +="\t<source src='"+playlist+"' type='video/mp4'>\n";
videoTag +="</video>\n"
$('#player'+index).html(videoTag);
window["vjPlayer"+index]=videojs("playerInstance"+index, {"autoplay": false, "preload": "auto" });
}
Play() and pause() and even currentTime() to get the current time works. But trying to set it just forces the player to go back to 0.
I'm working in a Mac in Chrome Version 86.0.4240.80 and Firefox Developer's Edition 71.0b1 (64-bit). These are all local files and I'm running it from http://localhost:8000/index.php.
In the video.js github channel, I figured out the answer to this question. I hadn't checked it on my server, so running the page locally screwed up the ability to click around and set currentTime. Quite strange, actually. I'm still not sure why it happens. You can see the comment here: https://github.com/videojs/video.js/issues/6900
Not the smartest move on my part, but hopefully this might help someone else in the future.

How can I turn on design mode in Gecko?

I am using Gecko browser in my program. I am trying to turn on design mode on this browser like that:
webBrowser1.Document.DomDocument.GetType().GetProperty("designMode").SetValue
(webBrowser1.Document.DomDocument, "On", null);
But it doesn't works. How can I do it?
nsIHTMLEditor is likely a per browser instance rather than a global instance (like things returned by Xpcom.GetService)
One can get a nsIEditor like this by (by supplying a Window instance)
var editingSession = Xpcom.CreateInstance<nsIEditingSession>("#mozilla.org/editor/editingsession;1");
nsIEditor editor = editingSession.GetEditorForWindow((nsIDOMWindow)Window.DomWindow);
Marshal.ReleaseComObject(editingSession);
(or you can just call the nsIEditor GeckoWebBrowser.Editor property.)
You may be able to cast this nsIEditor to a nsIHtmlEditor (although I have yet to try it)
GeckoWebBrowser browser = .....;
// Untested code
nsIHTMLEditor htmlEditor = (nsIHTMLEditor)browser.Editor;
The VB code from #GreenBear
Dim gEditor As nsIHTMLEditor:
gEditor = Gbrowser.Editor:
gEditor.DecreaseFontSize()

How to use wxBusyInfo?

I have encountered a problem with wxBusyInfo.
I want to disable user's operation when doing some calculation.
I just write the code like this:
wxWindowDisabler disableAll;
wxBusyInfo info(_T("Working, please wait..."), this);
for(int i = 0; i < 1; i++)
{
Install();
}
In the Install() function, I do some work like this:
wxSleep();
wxExecute(cmd, output, errors);
When I run the application, the busyinfo dialog will show up, but it will no longer at the top of the application. Also after I click the application, or click the busyinfo dialog, it will turn out like the pictures attached. When the Install() function finished, it will be ok. But I don't want users can end the application by that way.
What's the problem? What can I do?
after click the applicatioin
after click the busyinfo dialog
You are calling wxExecute synchronously, which means that it does not return until cmd completes. So you application does not get a chance to update the display.
So, you need to call wxExecute asynchronously.
The snag is that you cannot then see the output and errors from the executed command.

Simplest way to get the PID of a recently launched application

I want to launch a file with a specified application, and I want the launched program to immediately become the frontmost window.
I know that I can do this as follows:
[[NSWorkspace sharedWorkspace] openFile:fileName withApplication:appName];
Then, if I can get the PID of that launched application, I can then do this to make that application frontmost:
NSRunningApplication* app = [NSRunningApplication
runningApplicationWithProcessIdentifier: PID];
[app activateWithOptions: NSApplicationActivateAllWindows];
The question I have is this: what is the simplest, quickest, and most reliable way to get this application's PID right after launching, so I can make sure that this application is frontmost?
This is not as straightforward as it might appear at first glance. For example, I need a process name in order to get the PID using Carbon calls, or via the application dictionary that is accessible via NSRunningApplication. However, in the general case, I don't always know what the process name is, and in some cases, the process name is an empty string.
Furthermore, I might have other instances of this same application already running, and I want to always get the PID of the specific instance of the application that I just launched.
Can anyone suggest a definitive, 100-percent reliable way to get the currently launched application's PID?
Or alternatively, is there a way to launch a given file with a specified application such that the application always opens as the frontmost app?
Have you tried using the other version of openFile which will allow you to deactivate your application, allowing the new application to take focus?
[[NSWorkspace sharedWorkspace] openFile:fileName withApplication:appName andDeactivate:YES];
It is definitely not easy to get the PID of an application. And that's how Apple likes it.. Those cheeky bastards.
I had to write this beast just to get the PID from a full path of an app I knew was running.. Hey it's easier than parsing ps aux !
Sorry if there are some of my own private functions in there but you can get the idea of how I went about it and what I tried to avoid along the way.
+ (NSUInteger)pidFromAppPath:(NSString*)path
{
NSRunningApplication *n = [[[NSWorkspace sharedWorkspace]runningApplications] filterOne:^BOOL(NSRunningApplication *runner) {
// optional: avoid totally faceless apps and "Desk Accesory"-type background apps.
if (runner.activationPolicy == NSApplicationActivationPolicyProhibited) ||
runner.activationPolicy == NSApplicationActivationPolicyAccessory)
return nil;
id runPath = [runner valueForKeyPath:#"bundleURL"];
NSString *runString = [runPath isKindOfClass:[NSString class]]
? runPath
: [runPath isKindOfClass:NSURL.class] ? [((NSURL*)runPath) path]
: nil;
// optional: filter out Google Chrome's mockery of a once sane process-table
if ( !runString
|| [[runString lastPathComponent]contains:#"Google Chrome Helper.app"]
|| [[runString lastPathComponent]contains:#"Google Chrome Worker.app"]
|| [[runString lastPathComponent]contains:#"Google Chrome Renderer.app"] )
return nil;
return [runString isEqualToString:path] ?: nil; // This is where you actually test to see if it's the same as the string passed in, lol.
}];
return n ? [n processIdentifier] : 11000; // if 11000 you messed up.
}
And voilá... NSLOG: Pid of /Applications/Utilities/Terminal.app is 46152