Last active
September 3, 2021 16:49
-
-
Save Caeous/bdf87ff80008ce4ad2b4ebb5d8f97753 to your computer and use it in GitHub Desktop.
Wake PC and Launch Moonlight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
export PATH=/usr/local/bin:$PATH | |
wake_app=wakeonlan # brew install wakeonlan | |
mac=99:97:F9:99:9B:9A | |
ip=192.168.1.199 | |
moonlight=/Applications/Moonlight.app/Contents/MacOS/Moonlight | |
app=RDP # App name in Moonlight | |
printf 'Waking up...' | |
$wake_app -i $ip -p 9 $mac | |
$wake_app -i $ip -p 7 $mac | |
$wake_app $mac | |
printf 'Waiting...' | |
((count = 100)) # Maximum number to try. | |
while [[ $count -ne 0 ]] ; do | |
ping -c 1 $ip > /dev/null # Try once. | |
rc=$? | |
if [[ $rc -eq 0 ]] ; then | |
((count = 1)) # If okay, flag to exit loop. | |
fi | |
((count = count - 1)) # So we don't go forever. | |
done | |
printf '\n' | |
if [[ $rc -eq 0 ]] ; then # Make final determination. | |
printf 'Launching...' | |
$moonlight stream $ip "$app" &>/dev/null & # Launch Moonlight | |
else | |
printf 'Timeout.' | |
fi | |
printf '\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment