Skip to content

Instantly share code, notes, and snippets.

@antonmry
Last active May 29, 2024 03:14
Show Gist options
  • Save antonmry/8bf2d07db75df538c385bfa1cd6d5cf2 to your computer and use it in GitHub Desktop.
Save antonmry/8bf2d07db75df538c385bfa1cd6d5cf2 to your computer and use it in GitHub Desktop.
This is script to auto on/off a Logitech light when the webcam is on/off in Mac. It requires hidapitester
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>litra-auto-on</string>
<key>ProgramArguments</key>
<array><string>/Library/LaunchDaemons/litra-auto-on.sh</string></array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
#! /bin/bash
# Download both files and https://github.com/todbot/hidapitester to /Library/LaunchDaemons/
# Execute the following commands to launch it on login
# sudo chown root:wheel /Library/LaunchDaemons/litra-auto-on.plist
# sudo chmod o-w /Library/LaunchDaemons/litra-auto-on.plist
# sudo launchctl load -w /Library/LaunchDaemons/litra-auto-on.plist
# For test it:
# launchctl start litra-auto-on
# tail -f /var/log/system.log
# Use 046D/C900 for older models
model="046D/C901"
# Change to your own path
hidapitester="/Library/LaunchDaemons/hidapitester"
log stream --predicate 'subsystem contains "com.apple.UVCExtension" and composedMessage contains "Post PowerLog"' | while read LOGLINE
do
[[ "${LOGLINE}" == *"On;"* ]] && eval "$hidapitester --vidpid $model --open --length 20 --send-output 0x11,0xff,0x04,0x1c,0x01"
[[ "${LOGLINE}" == *"Off;"* ]] && eval "$hidapitester --vidpid $model --open --length 20 --send-output 0x11,0xff,0x04,0x1c"
done
@er-minio
Copy link

The script I am using (ijcarson1's one above) started working correctly after rebooting the computer a couple of times. No idea why.

@ekrapfl
Copy link

ekrapfl commented Oct 12, 2023

I think I finally got it for my setup (MacBook Pro M1 Ultra)
I used this script:

log stream --predicate 'eventMessage contains[c] "cameras changed to "' | while read LOGLINE;

do
  # ON
  [[ "${LOGLINE}" == *"changed to [ControlCenterApp.VideoCamera"* ]] && eval "$hidapitester --vidpid $model --open --length 20 --send-output 0x11,0xff,0x04,0x1c,0x01";
  # OFF
  [[ "${LOGLINE}" == *"changed to [:]"* ]] && eval "$hidapitester --vidpid $model --open --length 20 --send-output 0x11,0xff,0x04,0x1c";
done

Note: I added [c] for case insensitivity (that is what was breaking between off and on), and I made sure to run these to reset:

launchctl stop litra-auto-on
sudo launchctl load -w /Library/LaunchDaemons/litra-auto-on.plist;
sudo launchctl load -w /Library/LaunchDaemons/litra-auto-on.plist;
# the next line errors, so not positive if it is necessary or not
sudo launchctl bootstrap system /Library/LaunchDaemons/litra-auto-on.plist
launchctl start litra-auto-on

Hope this helps someone!

@aronrosenberg
Copy link

Hi Everybody,

Just a note that we have now integrated official support for Litra Lights being turned automatically on/off in the October 2023 release of GHub. This version will roll out to all users over the next week or two.

@aardvark82
Copy link

aardvark82 commented Oct 19, 2023

Excellent news! Thank you Aron & Logitech engineering team. Quick question - will this be supported in LogiOptions + as well or do we have to install both GHub for the Litra and logioptions+ separately for other devices?

@aronrosenberg
Copy link

This is only supported in GHub right now.

@Agusum
Copy link

Agusum commented Oct 26, 2023

Thanks for adding this feature to GHub!

Now all I need is to be able to manually turn it off using one of the programmable keys in my Logitech MX Keys. @aronrosenberg Are you looking to enable that feature?

@aronrosenberg
Copy link

You should already be able to assign Litra actions to a G key, just look for it under the assignments section for your keyboard.

@Agusum
Copy link

Agusum commented Oct 26, 2023

The Logitech MX Keys doesn't have G keys and it's not detected by GHub, only Logi Options+.

image

@aronrosenberg
Copy link

I missed the part where you said you had a MX Keys. That device is currently only supported in Options+ which does not have the Litra auto-on/off functionality at this time.

@Agusum
Copy link

Agusum commented Oct 27, 2023

Ideally there will only be one software for everything but I can live with having the auto on/off in GHub, if I'm able to have Smart actions for the light in Options+ to toggle it on/off manually, which are missing.

@patrickrushton
Copy link

@aronrosenberg Nice that this is now supported by Logitech G-Hub. Is there any progress with a native Apple Silicon version that doesn't require Rosetta?

@timtrinidad
Copy link

I enjoyed the feature in G-Hub but unfortunately G-Hub also caused lots of problems with my Yeti Mic. https://www.reddit.com/r/LogitechG/comments/oypw43/logitech_ghub_update_breaks_blue_yeti_mic/

The version in https://gist.github.com/antonmry/8bf2d07db75df538c385bfa1cd6d5cf2?permalink_comment_id=4723193#gistcomment-4723193 worked well for me, except that it would turn on whenever my phone came near my computer (i.e. the continuity camera logs triggered the light to turn on). This was the script I have that is working well. Note the addition of bundleNames:

model="046D/C900"
hidapitester="/Library/LaunchDaemons/hidapitester"

log stream --predicate 'eventMessage contains[c] "cameras changed to "' | while read LOGLINE;

do
  # ON
  [[ "${LOGLINE}" == *"changed to [ControlCenterApp.VideoCamera"*"bundleNames"* ]] && eval "$hidapitester --vidpid $model --open --length 20 --send-output 0x11,0xff,0x04,0x1c,0x01";
  # OFF
  [[ "${LOGLINE}" == *"changed to [:]"* ]] && eval "$hidapitester --vidpid $model --open --length 20 --send-output 0x11,0xff,0x04,0x1c";
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment