Get focus back after ShowURL()

Hi Folks,

I use ShowURL() to launch a particular website that downloads some data I need. For reasons I won’t go into here, I cannot launch this website from within my Xojo app using the HTMLViewer.

As it should, ShowURL() transfers the OS’s focus to the system’s default browser. Fine. But is there a way to bring it back to my app? I can use some logic I already have in place to know when the URL has completed loading. I just can’t figure out how to change the OS focus.

I’m mainly interested in XOS and have searched for terminal commands I can invoke via Shell() but nothing has jumped out as the right way to do this.

Thank you,


On macOS you can use the following code:

Declare Function NSClassFromString Lib "Foundation" (cls As CFStringRef) As Ptr
Declare Function currentApplication Lib "AppKit" Selector "currentApplication" (p As Ptr) As Ptr
Declare Sub activateWithOptions Lib "AppKit" Selector "activateWithOptions:" (appptr As Ptr, options As Integer)

Dim thisApp As Ptr = currentApplication(NSClassFromString("NSRunningApplication"))
activateWithOptions(thisApp, 2)

Be very careful with this though. it’s considered bad form to steal the focus from other apps.

Thanks. I’ll give this a try.

And I agree with you that I’m not happy at all I’m going down this path. My core issue is the security/data restrictions of getting the data I’m after require me to use an external browser. Really lame.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.