Skip to content

Instantly share code, notes, and snippets.

@dardo82
Last active September 14, 2018 23:34
Show Gist options
  • Save dardo82/66ab5f1947de0186dfbf to your computer and use it in GitHub Desktop.
Save dardo82/66ab5f1947de0186dfbf to your computer and use it in GitHub Desktop.
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
Copy link
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