USB Toggled Menu Bar Icon

I want to display a menu bar button whenever I connect a specific USB device, and want it to disappear when disconnecting the specific USB device. How would I go about achieving this?

1 Like

Menu bar icon, I don't know. But you can combine the actions connect/disconnect USB device with show/hide a floating menu. At least I think so. :innocent:

This will require the most current version released yesterday:

Define a menubar item in "Automations, Named & Other Triggers". Then right-click it and choose "Copy Selected Item UUID"

Then add a new USB Device Did Connect and a new USB Device Did Disconnect trigger. Use the predefined action "Run Apple Script" and run these scripts:

To show the item:

tell application "BetterTouchTool" to update_trigger "7093C95A-0AF7-42B3-8680-C7AD2D2BE7AB" json "{BTTEnabled : true, BTTEnabled2 : true}"

To hide the item:

tell application "BetterTouchTool" to update_trigger "7093C95A-0AF7-42B3-8680-C7AD2D2BE7AB" json "{BTTEnabled : false, BTTEnabled2 : false}"

(replace the UUID with the one you copied).

One limitation of this approach is, that the item will always be inserted at the very left.

Alternatively you can hide it, but this will leave a little gap:

	tell application "BetterTouchTool" to update_menubar_item "3EBB16B4-09B9-4120-BBD4-C09535AF8EEE" hidden true
2 Likes

This works great for my use case! There is an issue with the disconnect though. The menu bar icon won't disappear unless I manually run the script.

Is it a logitech device?

It's an ID Card reader

mhh, there have been some issues with some devices not triggering the disconnect notification - so far I know know about Logitech devices. Could you check whether the disconnect trigger is triggering at all? (e.g. check the "Show HUD" option on the trigger)

I just ran the script with the Show HUD option on the trigger and it didn't trigger the HUD.

Unfortuantely then there is currently no way to make this work. I'll soon try to figure out why the disconnect is not happening for some devices.

(Make sure all the values of the device are correctly entered, but that you probably did already)

1 Like

After further inspection, I ended up switching the Product and Vendor IDs in the USB Device Did Disconnect trigger. After switching them back to their correct values, this worked flawlessly. Thanks for your help!

1 Like

Gah I wanna update so bad but it’s gonna mean another 2 months waiting for IT approval. It was an uphill battle to get approval in the first place. And now that it’s saved in /Applications instead of ~/Applications I don’t have read/write to it. The release notes are up, yeah?

can’t you just download the current version manually? Index of /releases

I was concerned that a new instance would require new permissions for accessibility, screen sharing, etc

mhh I believe it should not, but I’m not quite sure :-/

Ha yep. Exactly where I’m at and very much not worth the risk to have to wait another 3 months and 500 feet of red tape. I’m about to upgrade on my personal machine right now though.

Well shit I guess I could test if it will require permissions on there

@Andreas_Hegenberg figured id update you on this. Apparently a new instance of BTT, even in an entirely separate directory (~/Applications vs /Applications) can piggyback on the permissions of the previous instance. So I am now up to date

Caveat: I have not tested what would happen if I delete the original instance

1 Like

That's what I had hoped because the signing certificates etc. are the same and the permissions are bound to signing information and not to the location. Deleting the original would probably have broken this as deleting would cause the whitelisting to be removed.

Then I’m very glad I didn’t lol.