# Get focus back after ShowURL()

**URL:** <https://forum.xojo.com/t/get-focus-back-after-showurl/62879>\
**Category:** Getting Started\
**Created:** [April 21, 2021, 10:40pm UTC](https://forum.xojo.com/t/get-focus-back-after-showurl/62879 "2021-04-21T22:40:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_W](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e47774/32.png) [@Dan\_W](https://forum.xojo.com/u/Dan_W)\
**Post date:** [April 21, 2021, 10:40pm UTC](https://forum.xojo.com/t/get-focus-back-after-showurl/62879/1 "2021-04-21T22:40:34Z")

</div>

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,

Dan

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [April 21, 2021, 11:45pm UTC](https://forum.xojo.com/t/get-focus-back-after-showurl/62879/2 "2021-04-21T23:45:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dan\_W](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e47774/32.png) [@Dan\_W](https://forum.xojo.com/u/Dan_W)\
**Post date:** [April 22, 2021, 12:39am UTC](https://forum.xojo.com/t/get-focus-back-after-showurl/62879/3 "2021-04-22T00:39:17Z")

</div>

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.
