Skip to content

Instantly share code, notes, and snippets.

@shinmiy
Last active May 14, 2020 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinmiy/a765d1442d057984ece915ccc135cd88 to your computer and use it in GitHub Desktop.
Save shinmiy/a765d1442d057984ece915ccc135cd88 to your computer and use it in GitHub Desktop.
ZoomとかGoogle Meetで会議中かを判定して隣の部屋のランプをつけるやつ。Bitbarで定期実行など。
#!/bin/bash
export PATH=$PATH:/usr/local/bin
function toggle_light() {
host='192.168.xxx.xxx'
if [ $1 -eq 0 ];then
/usr/local/bin/tplink-smarthome-api setPowerState $host false
else
/usr/local/bin/tplink-smarthome-api setPowerState $host true
fi
}
# Search for Zoom meetings
# (i.e. Window with title "Zoom Meeting")
# https://stackoverflow.com/a/14552852
# https://hacknote.jp/archives/35775/
zoom_result=0
echo '
tell application "System Events"
set allWindows to name of window of processes whose visible is true
end tell
return allWindows
' | osascript - | grep -q "Zoom Meeting" || zoom_result=$?
# Search for Google Meet meetings
# (i.e. Chrome tab with url "https://meet.google.com/aaa-bbbb-ccc")
# https://gist.github.com/samyk/65c12468686707b388ec43710430a421
meet_result=0
echo '
set urls to ""
tell application "Google Chrome"
set window_list to every window # get the windows
repeat with the_window in window_list # for every window
set tab_list to every tab in the_window # get the tabs
repeat with the_tab in tab_list # for every tab
set urls to urls & the URL of the_tab & "\n"
end repeat
end repeat
end tell
return urls
' | osascript - | grep -qE "https\:\/\/meet\.google\.com\/[a-z]{3}\-[a-z]{4}-[a-z]{3}" || meet_result=$?
if [ $meet_result -eq 0 ] || [ $zoom_result -eq 0 ];then
echo ":bulb:InMtg"
echo ---
date +"%Y-%m-%d %k:%M:%S"
toggle_light 1
else
echo ":bulb:Off"
echo ---
date +"%Y-%m-%d %k:%M:%S"
toggle_light 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment