Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FW webcam USB light
#!/bin/zsh
# Use an USB light to let FW webcam see
PATH=$PATH:/usr/local/bin
UHCOPTS=$(uhubctl | awk '{ text=text"\n"$0; if ($0~/hub/) text=$0; if (text~/power$/) { print text; text="" } }' \
| awk -F',| |:' -v ORS=" " '{ print $5 }' | awk '{ print "-p "$2" -l "$1 }')
if [ -n "$UHCOPTS" ]; then
uhubctl -a 0 ${=UHCOPTS}
DEVNAME="iSight"; DEVGUID=$(system_profiler SPCameraDataType | awk -v dev="$DEVNAME:" -F':|x|-' '{ if ($0~dev) n=NR; if (NR==n+3 && NR!=3) print $3 }')
IOFWUCC=$(ioreg -r -n IOFireWireDevice@$DEVGUID | awk -F'"' '/IOUserClientClass/ { print $4 }')
RNUMBER=$(ioreg -r -n IOFireWireDevice@$DEVGUID | awk -F' |>' -v ucc=" $IOFWUCC " '{ if ($0~ucc) { print $17; exit } }')
while [ -n "$RNUMBER" ]; do
OLDRNUM=$RNUMBER
RNUMBER=$(ioreg -r -n IOFireWireDevice@$DEVGUID | awk -F' |>' -v ucc=" $IOFWUCC " '{ if ($0~ucc) { print $17; exit } }')
if [ $OLDRNUM -eq 5 -a $RNUMBER -eq 6 ]; then
uhubctl -a 1 ${=UHCOPTS}
fi
if [ $OLDRNUM -eq 6 -a $RNUMBER -eq 5 ]; then
uhubctl -a 0 ${=UHCOPTS}
fi
sleep 1
done
fi
#!/bin/sh
HL="$HOME/Library"; HLASCLA="$HL/Application Support/Camera Lights Action"; HLLA="$HL/LaunchAgents"
chmod a+rx cla.sh; mkdir $HLASCLA; cp cla.sh $HLASCLA; cp it.dardo82.CameraLightsAction.plist $HLLA
launchctl load -w "$HLLA/it.dardo82.CameraLightsAction.plist"
<?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>it.dardo82.CameraLightsAction</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Application Support/Camera Lights Action/cla.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
#!/bin/sh
HL="$HOME/Library"; HLASCLA="$HL/Application Support/Camera Lights Action"; HLLA="$HL/LaunchAgents"
launchctl unload "$HLLA/it.dardo82.CameraLightsAction.plist"
@dardo82

This comment has been minimized.

Copy link
Owner Author

dardo82 commented Oct 15, 2015

Turns on USB leds using uhubctl when the webcam is activated and turns them off when it is deactivated.
It depends on uhubctl to turn on and off the USB lights that can be found here: http://github.com/mvp/uhubctl.
This works with Apple external iSight and maybe other FireWire webcams changing the DEVNAME variable.

@mvp

This comment has been minimized.

Copy link

mvp commented Nov 20, 2015

Hi, I'm the author of uhubctl. Nice to see you using it in some inventive ways :)
This script looks quite ugly, all just to find which port to turn on/off.
I had this idea for a while: add feature to uhubctl to be able to specify which port to control not by number, but by identity of connected USB device: vendor, device type, or device serial number.
The only issue with that approach that it will work to turn off, but not to turn on: if device is off, we could not possibly know which port to operate on, unless we remembered it beforehand.

@dardo82

This comment has been minimized.

Copy link
Owner Author

dardo82 commented Feb 1, 2016

It would be obviously very useful, can i help you about that?

@mvp

This comment has been minimized.

Copy link

mvp commented Feb 23, 2016

Ok, thanks for input. I will start coding it, and will commit when ready - may take a week or two.
You can help by pushing it into homebrew: https://github.com/Homebrew/homebrew-head-only/pull/172 - I cannot comment on that thread, unfortunately. Thanks!

@dardo82

This comment has been minimized.

Copy link
Owner Author

dardo82 commented Feb 27, 2016

I can't, too... Sorry. :-/
Anyway, the ports are on by default so we can note which port is that before turning it off and then remember it to turn it on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.