# Hook in firefox leaves location bar focused

**URL:** <https://discourse.hookproductivity.com/t/hook-in-firefox-leaves-location-bar-focused/4221>\
**Category:** Bug Reports\
**Created:** [December 2, 2021, 9:06pm UTC](https://discourse.hookproductivity.com/t/hook-in-firefox-leaves-location-bar-focused/4221 "2021-12-02T21:06:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jenji](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/jenji/32/1945_2.png) [@jenji](https://discourse.hookproductivity.com/u/jenji)\
**Post date:** [December 2, 2021, 9:06pm UTC](https://discourse.hookproductivity.com/t/hook-in-firefox-leaves-location-bar-focused/4221/1 "2021-12-02T21:06:25Z")

</div>

Hey all, new user here.

When I fire up hook using ^H with Firefox focused, it looks like applescript is selecting the location bar and copying the value, but not returning the focus to where it was in the main frame.

I use vimium to navigate web pages, and it doesn’t work when the page itself isn’t focus. This breaks the flow of what I was doing, as I have to mess around to get back to the web content.

is it possible to return the focus where it started when collecting the url?

---

<div class="post-metadata">

**Author:** ![bchend](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/b/dbc845/32.png) [@bchend](https://discourse.hookproductivity.com/u/bchend)\
**Post date:** [December 3, 2021, 7:22pm UTC](https://discourse.hookproductivity.com/t/hook-in-firefox-leaves-location-bar-focused/4221/2 "2021-12-03T19:22:05Z")

</div>

Sorry for the trouble.

Hook has to use UI scripting to get the current url from Firefox. So there are some problems.

Here is a modified script. It seems to be working fine on my machine. Could you please open Hook preferences window → Script → Firefox → Get Address, replace the Get Address script with the following script?

```auto
use framework "AppKit"
-- classes, constants, and enums used
property NSShiftKeyMask : a reference to 131072
property NSAlternateKeyMask : a reference to 524288
property NSControlKeyMask : a reference to 262144
property NSEvent : a reference to current application's NSEvent

set modifier_down to true
repeat while modifier_down
    set modifier_flags to NSEvent's modifierFlags()
    set option_down to ((modifier_flags div (get NSAlternateKeyMask)) mod 2) = 1
    set shift_down to ((modifier_flags div (get NSShiftKeyMask)) mod 2) = 1
    set control_down to ((modifier_flags div (get NSControlKeyMask)) mod 2) = 1
    set modifier_down to option_down or shift_down or control_down
end repeat

tell application "Firefox"
    activate
    delay 0.05
    set myName to get name of front window
    if version > 72 and myName ends with " - Mozilla Firefox" then
        if length of myName > 18 then
            set myName to text 1 through -19 of myName
        else
            set myName to ""
        end if
    end if
end tell
tell application "System Events"
    keystroke "l" using {command down}
    keystroke (key code 53)
    keystroke (key code 53)
    --keystroke "c" using {command down}
    tell process "Firefox"
        click menu item "Copy" of menu "Edit" of menu bar 1
    end tell
    delay 0.05
    set theClipboard to current application's NSPasteboard's generalPasteboard's stringForType:(current application's NSPasteboardTypeString)

	keystroke (key code 53)
	keystroke (key code 48)
    return ("[" & myName & "](" & the theClipboard as string) & ")"
end tell

```

---

<div class="post-metadata">

**Author:** ![jenji](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/jenji/32/1945_2.png) [@jenji](https://discourse.hookproductivity.com/u/jenji)\
**Post date:** [December 3, 2021, 9:34pm UTC](https://discourse.hookproductivity.com/t/hook-in-firefox-leaves-location-bar-focused/4221/3 "2021-12-03T21:34:23Z")

</div>

That does not work - it leaves the cursor focused on the “reading mode” toggle. Given that you’re just adding key presses, you’ll probably have better luck with F6 (keycode 97).

I tested it with F6, and it does work. That being said… there has to be a better way of automating this. I’ve got a few other apps that observe what I’m doing, like Timing, and it can get a surprising amount of data passively, without controlling and interacting with the application.

---

<div class="post-metadata">

**Author:** ![bchend](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/b/dbc845/32.png) [@bchend](https://discourse.hookproductivity.com/u/bchend)\
**Post date:** [December 6, 2021, 5:19pm UTC](https://discourse.hookproductivity.com/t/hook-in-firefox-leaves-location-bar-focused/4221/4 "2021-12-06T17:19:32Z")

</div>

> [@jenji](#):
>
> there has to be a better way of automating this. I’ve got a few other apps that observe what I’m doing, like Timing, and it can get a surprising amount of data passively, without controlling and interacting with the application.

Thank you for info. We will have a look.
