# Xbar Script: Show count of hooked documents in menu bar

**URL:** <https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551>\
**Category:** Showcases and Use Cases\
**Created:** [January 19, 2022, 4:46pm UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551 "2022-01-19T16:46:29Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![floflo](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/f/6f9a4e/32.png) [@floflo](https://discourse.hookproductivity.com/u/floflo)\
**Post date:** [January 19, 2022, 4:46pm UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/1 "2022-01-19T16:46:29Z")

</div>

Hi, this is a simple script for [xbar](https://xbarapp.com/) that shows the count of documents hooked to the currently active window/item in the menu bar.

**Update** : A few people pointed out that the script has conflicts with apps where Hook relys on UI-Scripting (e.g. Firefox).

> <https://gist.github.com/flegfleg/289f6934f82fd8d1b82d969a1dc7a1d2>

 ![CleanShot 2022-01-19 at 17.40.33](https://discourse.hookproductivity.com/uploads/default/original/2X/5/594392c466a667c6ed05933e2e15a899daf0a0b4.jpeg)  
 ![CleanShot 2022-01-19 at 17.40.23@2x](https://discourse.hookproductivity.com/uploads/default/original/2X/1/17f2379b4e4655e958d63094a35f9c0818151a8c.jpeg)

---

<div class="post-metadata">

**Author:** ![thomasg](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/thomasg/32/1906_2.png) [@thomasg](https://discourse.hookproductivity.com/u/thomasg)\
**Post date:** [January 20, 2022, 12:48am UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/2 "2022-01-20T00:48:08Z")

</div>

This is fantastic - thank you so much!

Edit: I’ve had this installed for about ten hours now and my Hook usage has already skyrocketed. Thanks thanks for introducing me to xbar, too, can’t believe I’d not seen this before now!

---

<div class="post-metadata">

**Author:** ![tberni](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/t/ecccb3/32.png) [@tberni](https://discourse.hookproductivity.com/u/tberni)\
**Post date:** [January 20, 2022, 11:37am UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/3 "2022-01-20T11:37:09Z")

</div>

Thank you very much @floflo for this contribution: as @thomasg says this script brings more usability to hook: I’m testing it and it changes the way I use hook too, but - unfortunately - I’ve detected a problem with **Mozilla Firefox** , with which I do a lot of linking via hook.

It turns out that when **xbar** with your **hook.1s.sh** plugin are active and “watching”, then the Firefox address window opens and closes intermittently, I suspect at the rate of 1second, I think, matching the 1-second “watch” rate that I think your script does. And therefore any possibility of using the browser is blocked. I have also found that with the Brave browser this interaction does not occur.

Have I explained myself well enough? Is there a possible hook-xbar-firefox triple interaction? **Is it possible to find a solution?**

Thank you very much for your attention.

---

<div class="post-metadata">

**Author:** ![tberni](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/t/ecccb3/32.png) [@tberni](https://discourse.hookproductivity.com/u/tberni)\
**Post date:** [January 20, 2022, 12:02pm UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/4 "2022-01-20T12:02:23Z")

</div>

One more fact:

Now I remember that Firefox’s behaviour of displaying the address bar always occurs when invoking hook to link, so I gather that the behaviour with xbar + hook.1s.sh suggests that at a rate of 1 second the address bar is displayed and closed as if it were a continuous invocation of hook.

---

<div class="post-metadata">

**Author:** ![floflo](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/f/6f9a4e/32.png) [@floflo](https://discourse.hookproductivity.com/u/floflo)\
**Post date:** [January 20, 2022, 1:50pm UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/5 "2022-01-20T13:50:06Z")

</div>

Hey TBerni, interesting problem… i could reproduce it with Firefox.  
The “Get Adress” command for Firefox uses UI-scripting-Applescript that seems to conflict with my Applescript. Not sure how/if i could resolve that, maybe the Hook developers have an idea?

---

<div class="post-metadata">

**Author:** ![floflo](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/f/6f9a4e/32.png) [@floflo](https://discourse.hookproductivity.com/u/floflo)\
**Post date:** [January 20, 2022, 1:50pm UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/6 "2022-01-20T13:50:44Z")

</div>

Thanks for the feedback, glad it’s useful for you!

---

<div class="post-metadata">

**Author:** ![tberni](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/t/ecccb3/32.png) [@tberni](https://discourse.hookproductivity.com/u/tberni)\
**Post date:** [January 20, 2022, 2:18pm UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/7 "2022-01-20T14:18:08Z")

</div>

Hello again @floflo:

I know from the developers that the level of compatibility between Firefox and Hook is not as high as that between Hook and Chromium-based browsers. In fact, I believe that the problem of the opening of the address bar - as I indicated - already exists between Firefox and Hook, what happens now with your script is that the problem becomes intractable due to the “surveillance” that hook.1s.sh exerts on Firefox and that determines the opening-closing-opening loop… in the address bar. (I don’t know how to express it in a more technical way).

I think your plugin is great, so I’m starting to think that I’ll have to use Brave as my first choice of browser instead of Firefox… Difficult dilemma!

Thanks again.

---

<div class="post-metadata">

**Author:** ![LucB](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/lucb/32/2228_2.png) [@LucB](https://discourse.hookproductivity.com/u/LucB)\
**Post date:** [January 21, 2022, 2:40am UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/8 "2022-01-21T02:40:46Z")

</div>

It’s not a Firefox specific issue. The problem is that some apps are [not truly linkable](https://hookproductivity.com/help/integration/data-linkability-and-why-it-matters/) (via an API), so for them Hook uses UI scripting, which involves automating interactions on the UI. (Hook Pro users can peer into Hook software integration scripts.)

Our solution will avoid this. It will only auto update the link count (in the separate window) if Hook can get the link info via automation.

---

<div class="post-metadata">

**Author:** ![tberni](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/t/ecccb3/32.png) [@tberni](https://discourse.hookproductivity.com/u/tberni)\
**Post date:** [January 21, 2022, 10:09am UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/9 "2022-01-21T10:09:46Z")

</div>

Thank you very much for your explanation @LucB: I suspected some of this.

**One question:** do you already have a forecast of when you will be able to implement an internal solution to Hook to be able to see the links through the menu bar or by notification? In which version do you think you will introduce it?

---

<div class="post-metadata">

**Author:** ![yfs](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/y/35a633/32.png) [@yfs](https://discourse.hookproductivity.com/u/yfs)\
**Post date:** [January 21, 2022, 2:14pm UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/10 "2022-01-21T14:14:09Z")

</div>

> [@floflo](#):
>
> that shows the count of documents hooked to the currently active window/item in the menu bar

It tells me

Make your script executable: chmod +x hook. 1s.sh

no idea what I have to do. Thanks for any help

---

<div class="post-metadata">

**Author:** ![yfs](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/y/35a633/32.png) [@yfs](https://discourse.hookproductivity.com/u/yfs)\
**Post date:** [January 21, 2022, 2:42pm UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/11 "2022-01-21T14:42:29Z")

</div>

> [@yfs](#):
>
> Make your script executable: chmod +x hook. 1s.sh

Found it in terminal … sorry for being dumb

---

<div class="post-metadata">

**Author:** ![LucB](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/lucb/32/2228_2.png) [@LucB](https://discourse.hookproductivity.com/u/LucB)\
**Post date:** [January 21, 2022, 8:38pm UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/12 "2022-01-21T20:38:57Z")

</div>

I hesitate to commit specific dates. If I were a betting man, I’d say this 1/2 year.

---

<div class="post-metadata">

**Author:** ![raguay](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/raguay/32/237_2.png) [@raguay](https://discourse.hookproductivity.com/u/raguay)\
**Post date:** [January 22, 2022, 4:18am UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/13 "2022-01-22T04:18:08Z")

</div>

Hi, This script isn’t usable for me. It keeps causing UI artifacts in many programs (FireFox, SideNote, etc). In a text editor, it is causing the cursor to move down the page one line at a time every second (NeoVim in a terminal). I suspect it’s due to UI scripting which often has this type of effect.

---

<div class="post-metadata">

**Author:** ![LucB](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/lucb/32/2228_2.png) [@LucB](https://discourse.hookproductivity.com/u/LucB)\
**Post date:** [January 22, 2022, 9:36pm UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/14 "2022-01-22T21:36:00Z")

</div>

yes, basically the script would need to check that Hook does not interact with the current app via UI scripting. I’d recommend checking whether the app is one of a set of apps, including Finder, DEVONthink, OmniFocus, Mail, etc.

---

<div class="post-metadata">

**Author:** ![floflo](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/f/6f9a4e/32.png) [@floflo](https://discourse.hookproductivity.com/u/floflo)\
**Post date:** [January 22, 2022, 9:37pm UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/15 "2022-01-22T21:37:24Z")

</div>

Sorry to hear that… i tested it with the apps i use every day, but it seems that none of them are dependent on UI-Scripting. I’ll add a note up top.

---

<div class="post-metadata">

**Author:** ![pug](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/p/51bf81/32.png) [@pug](https://discourse.hookproductivity.com/u/pug)\
**Post date:** [February 16, 2022, 2:00am UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/16 "2022-02-16T02:00:14Z")

</div>

Great script @floflo - thanks for making this! Since I’m not using Firefox, only Brave and Safari, this is just perfect for my work. To improve the aesthetics and usability, I changed the IF-THEN-ELSE part slightly and moved the xbar item next to the Hook icon in the menubar so it looks like this (to the left):

![Skärmavbild 2022-02-16 kl. 02.36.10](https://discourse.hookproductivity.com/uploads/default/original/2X/4/4d96289bbbd4b13e379295fb8fc25f980741c5cf.png)

I find it a bit more intuitive and sleek this way.  
It’s easy to change the script to whatever color you want on the figure - I prefer red because it has good contrast in both dark and light mode.

```auto
if (($count > 0)) 
then 
	echo "$count | color=red | size=14"
else 
	echo ""
fi

```

---

<div class="post-metadata">

**Author:** ![hayes1699](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/h/a5b964/32.png) [@hayes1699](https://discourse.hookproductivity.com/u/hayes1699)\
**Post date:** [February 23, 2023, 6:19pm UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/17 "2023-02-23T18:19:14Z")

</div>

Im having the same issue and am dumb. what was the solution here?

---

<div class="post-metadata">

**Author:** ![LucB](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/lucb/32/2228_2.png) [@LucB](https://discourse.hookproductivity.com/u/LucB)\
**Post date:** [February 28, 2023, 4:53am UTC](https://discourse.hookproductivity.com/t/xbar-script-show-count-of-hooked-documents-in-menu-bar/4551/18 "2023-02-28T04:53:15Z")

</div>

Welcome to the Hookmark Forum , @hayes1699, and thanks for asking.

Hookmark can show hook counts in its menu bar icon for AppleScript-automated apps [General Preferences Tab – Hookmark](https://hookproductivity.com/help/preferences/general). Firefox is not link-friendly with respect to automation but plenty of apps are.
