Skip to content

Instantly share code, notes, and snippets.

@ariankordi
Created May 18, 2024 05:21
Show Gist options
  • Save ariankordi/ee8682d6de16df13f4983c6cd1fabe86 to your computer and use it in GitHub Desktop.
Save ariankordi/ee8682d6de16df13f4983c6cd1fabe86 to your computer and use it in GitHub Desktop.
todo i gotta rewrite both in python hhhh
#!/bin/bash
pw=$(ffmpeg -hide_banner -loglevel fatal -video_size 720x480 -f v4l2 -ss 1 \
-i /dev/v4l/by-id/usb-Elgato_Game_Capture_HD60_X_*-video-index0 \
-frames:v 1 -f apng - \
| zbarimg --quiet --raw --oneshot - \
| awk -F ';' '{printf substr($3, 3)}')
if [ ! -z "$pw" ]; then
nmcli connection modify ENTER_SWITCH_SSID_HERE wifi-sec.psk "$pw"
nmcli r wifi on
nmcli c down ENTER_SWITCH_SSID_HERE
nmcli c up ENTER_SWITCH_SSID_HERE
xdg-open http://192.168.0.1/index.html
else
notify-send 'no qr found or command failed otherwise'
fi
#!/bin/bash
# cannot remember why this would not work with sh
# but as of 2024-02-27 for the new error handling it uses bash features
# TODO: we should probably move all scripts that have been moved from sh to bash, to use [[ instead of [
export PATH=/opt/homebrew/bin:$PATH
pw_str=$(ffmpeg -hide_banner -loglevel fatal -f avfoundation -ss 1 \
-framerate 60 -video_size 1280x720 -i "Game Capture HD60 X:" \
-frames:v 1 -f apng - \
| zbarimg --quiet --raw --oneshot -)
# failed error checking code because idk if we can get ffmpeg's stderr preserving its stdout
#if [[ $error == *"input/output error"* ]]; then
# Check if the error variable contains "input/output error"
#if echo "$error" | grep -q "nput/output error"; then
# osascript -e 'display notification "likely something is using the cap card" with title "switch qr connect: i/o error"'
# exit
#fi
pw=$(echo $pw_str | awk -F ';' '{printf substr($3, 3)}')
ssid=$(echo $pw_str | awk -F ';' '{printf substr($1, 8)}')
if [ ! -z "$pw" ]; then
networksetup -setairportpower en0 on
osascript -e "display notification \"retrieved SSID: $ssid, password: $pw\" with title \"now connecting to switch's wi-fi...\""
# enable wifi then remove network before readding it
# TODO: consider removing this if it does more harm than good
# for instance it can override "do not automatically connect" setting
networksetup -removepreferredwirelessnetwork en0 "$ssid"
networksetup_output=$(networksetup -setairportnetwork en0 "$ssid" "$pw")
if [ -n "$networksetup_output" ]; then
osascript -e "display notification \"connection failed: $networksetup_output\" with title \"networksetup return code $?\""
else
# switch ip address and default web server
open http://192.168.0.1/index.html
fi
else
osascript -e 'display notification "no qr found or command failed otherwise" with title "switch qr connect failed"'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment