# [HOW TO] Remote PC (VPN, Wake on Lan, Microsoft Remote Desktop)



## notimp (May 14, 2020)

Here is a quick How To on how to set up a remote Windows PC on your home network, how to create a VPN tunnel to VPN into that network remotely, how to use Wake on LAN to wake up that Windows PC remotely, and how to then use Microsoft Remote Desktop to work on that PC, from anywhere in the world. 

I just set this up for a new Desktop I built, and this is a writeup of that process.

It will go into detail on almost every step - except for one. My ISP already provides me with a static public IP address (that only changes once every few years), so I didnt have to set up Dynamic DNS, to be able to address my router (and home network) from the internet at large. I already have and know that IP. So if you have a dynamically changing IP address that gets assigned to you by your ISP - you are on your own on that one. 
(Usually google DDNS and your router firmware (f.e. Tomato (see https://old.reddit.com/r/TomatoFTW/ )), to get pointed into the correct direction.  )

1. Setting up Wake on LAN (WOL).
Not as easy as you'd think.  Windows requires quite a few settings to be changed for this, and it is dependent on your motherboard/motherboard vendor as well. And on your router (more on that later). Here are the steps for an ASUS mainboard under Windows 10:

Follow all of those steps:
https://rog.asus.com/forum/showthread.php?93081-HERO-Wake-on-LAN#post693575
(Then it still didnt work for me.  )

Then follow those steps as well:

```
WINDOWS...
Open device manager, find your NIC, open, drivers tab - Update driver. If nothing found, download directly from manufacturer website
Once updated, reboot.
After reboot, open NIC properties\Power Management tab:
Tick all boxes - Allow computer to turn off device, allow to wake up, only allow magic packet.
Open NIC properties\Advanced tab and (where available):
Set Enable PME = ENABLED
Set Energy Efficient Ethernet / Green etc = DISABLED
Wake on Magic Packet = ENABLED
Wake on Pattern Match = ENABLED
Reboot, then after reboot shutdown.
```
(src: https://rog.asus.com/forum/showthre...ing-from-shutdown-Asus-Deluxe-Z170#post714468 (minus the registry tweak which wasn't needed. I already edited it out in the code box above))

After that the Asus motherboard and Windows 10 were set up and ready for WOL.

But then your router still can block or not forward the magic packet (the thing that makes your PC turn on via LAN) - so that is also something you have to sort out. 

My router runs under Tomato (open source firmware), which has a 'Wake on LAN' feature in the tools section, where you just enter the Mac address of your PCs NIC (network card) in a textbox, and hit wake - which will wake up that PC always. Which is good for testing, but we'll make sure that magic packets to wake up the PC can be sent from other devices as well. 

Power usage for my PC (ROG Strix B450-I motherboard) shut down, with WOL still possible is about 1.75 watt, but you should check yours to make sure your's is not 10+ times higher.  (Depends on the powersupply and motherboard.)

2. Once WOL works for you, you can install "Microsoft Remote Desktop" (on the device that will control the PC) and "Microsoft Remote Desktop Assistant" (on the PC = device that will be controlled). Both are free. I also would encourage you to buy Synergy ( https://symless.com/synergy ), which allows you to seamlessly and wirelessly share one devices (f.e. laptop) keyboard and mouse, with the PC you are trying to control. Synergy works better, if you are in the same room as the PC and have a monitor thats on - and just want to control that PC from a laptop f.e.. So no screen mirroring. "Microsoft Remote Desktop" would be what you'd use if you need screen mirroring (f.e. because your monitor is turned off, or you are remoting in from anywhere in the world (and arent in the same room)).

(If you use a Macbook to control a Windows PC via Synergy - you need to enter your Macs IP address on the PC side, network address translation with the Macs name doesnt seem to work in Synergy.  )

With that you now can turn on and remotely control the Windows PC from within your home network.

As we also want this to work from anywhere in the world, the next step is to talk a bit about router choice.
-

As you basically need to set up a VPN tunnel on your router, so you can VPN into your home network - you need a router that supports that. If you are new to this, and want to get this to work on the cheap, I'd recommend an Asus RT-AC66U router (used for under 100 bucks, I got mine for 70USD a while back), running on a replacement open source firmware. I personally use Tomato (open source firmware) - so all the following steps are written for Tomato specifically, but also should give you an idea about what steps you'd go through in general.

Also - with flashing your router to a replacement open source firmware, you are on your own.  You can brick them in the process - which is why I recommended you get a cheap enough, but still good, router if you are starting out..  (Asus RT-AC66U)
-

3. Making sure you can send wake on lan magic packets from other devices (not just the router) on Tomato.
Tomato kicks devices that are turned off out of the ARP cache after a while, which prevents them from being turned on via WOL from other devices (lets say a laptop). They can always be turned on remotely via the Tools/Wake on Lan menu in Tomato (the router menu), but there is also a work around in the form of a Tomato firewall script that fixes the issue.

You can set that up by following this tutorial
https://justinmontgomery.com/wake-on-lan-configuring-your-pc-tomato-iphone

There also is a part in there that tells you to set a UDP port forward to that 192.168.1.254 address, which you should do as well (so WOL later works over the VPN as well). Also ff:ff:ff:ff:ff:ff in that tutorial is not a placeholder, but the real deal.  Later on you are addressing 192.168.1.254 with the MAC address of the device you want to wake up, and Tomato does the rest.

After following those steps, waking up the PC should work from any device in the network, always.

4. Setting up the OpenVPN Server on your Tomato router

For this, you first need to generate your OpenVPN certificates and keys.

I did this on MacOS, following this tutorial
https://firxworx.com/blog/it-devops...eys-for-openvpn-server-with-easyrsa-on-macos/

It first walks you through installing XCode, and brew, and then through the entire certificates/key generation process. (Using 2048 key size is fine for Tomato on the RT-AC66U)

Depending on the OS you are using to generate the key pairs, your process might vary - but you can use the tutorial to look up all the certificates/keys that need to be generated, as well as how EasyRSA ( https://github.com/OpenVPN/easy-rsa/releases ) would be used to generate them. There also is a windows version of EasyRSA you could use, where the certificates/keys generation process should be similar.

Once you have all your certificates and keys, you can set up the OpenVPN Server in Tomato, using them, with the help of the following blogpost -

DISCLAIMER: Only use the images in the following blogpost to guide you through setting up the OpenVPN Server. (Dont use any of the info on generating the certificates or keys - we already did that.  If you only stick to the images, they'll tell you everything thats needed.  )
https://lassesunix.wordpress.com/20...n-a-tomato-router-with-tunnelblick-as-client/

Once the server is set up (using the config options from the images above, and your keys (content of your key files)) and running, you only need to provide your VPN client of choice the ca.crt, and the client .crt and .key files (all generated with EasyRSA in the steps before), in addition to a configuration file that tells it the server side settings.

Most VPN clients can use a config.ovpn file for that, which you would generate with a texteditor and drop into the same folder as the ca.crt, and the client .crt and .key files - and that in my case looks as follows:

```
client
dev tun
proto udp
remote 55.255.55.255 1194
resolv-retry infinite
nobind
persist-key
persist-tun

ca ca.crt
cert androidclient.crt
key androidclient.key
ns-cert-type server
comp-lzo
verb 4
float
```

Make sure you replace 55.255.55.255 with the public IP of your home network, and androidclient.crt and androidclient.key with the names of your client .crt and .key files respectively (EasyRSA allowed you to name those freely. In the tutorial it was suggested you create one for every client that would be connecting to your VPN tunnel on the router (Android Phone, Mac Laptop, ...). Then save the textfile.

Usually doubleclicking the config.ovpn should be enough to finally import the VPN credentials into your VPN client software of choice (it is f.e. for Tunnelblick), but that may vary depending on the VPN software you use. Still you should have everthing thats necessary at this point.

The next step is to test out if your VPN connection to your home router (running Tomato) is working (which it should at this point  ), f.e. by using your smartphones hotspot as an internet connection, and then trying to VPN into your home network.  If it works, yay for you.. 
--

5. Once the VPN connection is established


- Waking up the PC using WOL via your home networks public IP and the port you defined should work. (Actually this should work regardless of you being VPN tunneled to your home network or not..  )

Here is an example how that command would look with wakeonlan (command line program that can be installed with brew on a Mac (brew install wakeonlan)):

```
/usr/local/bin/wakeonlan -i 55.255.55.255 -p 8089 d4:4d:64:46:51:15
```
Where
55.255.55.255 would be your public IP
8089 the port (UDP) you forwarded 192.168.1.254 to in Tomato
and
d4:4d:64:46:51:15 the MAC address of the PC you are trying to wake up.

After your PC has been woken up, give it some time to boot, and then connect with Microsoft Remote Desktop - and thats basically all.  (Synergy in my case doesnt work if you are tunneld in via a VPN, but usually you wouldnt want to use that from a remote location anyhow.  )
-

All thats left for me is to leave you with a MacOS applescript (save as an .app with Script Editor) to wake your PC and either start Synergy or Microsoft Remote Desktop - in case you are using a Macbook to remote into your PC (wakeonlan needs to be installed via brew ( https://brew.sh/ )):

```
set x to isAppLoaded("Synergy")
if x then
    do shell script "curl -X POST https://maker.ifttt.com/trigger/HDMI2/with/key/00000yoRGEN000kkF00000"
    do shell script "ps aux  |  grep -i Synergy  |  awk '{print $2}'  |  xargs kill -9 & $COMMAND & $EXIT"
else
    display dialog "Local or Remote?" with title "Chose connection method" buttons {"Local", "Remote", "Cancel"} default button "Local" cancel button "Cancel"
    if the button returned of the result is "Remote" then
        do shell script "/usr/local/bin/wakeonlan 192.168.1.254 d4:4d:64:46:51:15"
        do shell script "/usr/local/bin/wakeonlan -i 55.255.55.255 -p 8089 d4:4d:64:46:51:15"
        delay 37
        tell application "Microsoft Remote Desktop"
            activate
        end tell
    else if the button returned of the result is "Local" then
        do shell script "/usr/local/bin/wakeonlan 192.168.1.254 d4:4d:64:46:51:15"
        do shell script "/usr/local/bin/wakeonlan -i 55.255.55.255 -p 8089 d4:4d:64:46:51:15"
        do shell script "curl -X POST https://maker.ifttt.com/trigger/HDMI4/with/key/00000yoRGEN000kkF00000"
        tell application "Synergy"
            activate
        end tell
    end if
end if

on isAppLoaded(app_name)
    tell application "System Events"
        set app_list to every application process whose name contains app_name
        if the (count of app_list) > 0 then
            return true
        else
            return false
        end if
    end tell
end isAppLoaded
```
If you choose local it will launch Synergy, if you choose remote it will wait 37 seconds (for the PC to boot) and then start Microsoft Remote Desktop.

And thats it. 

Potential use cases? I don't know, I just set it up..  Remote gaming via Microsoft Remote Desktop is kind of out of the question (latency), also GOG Galaxy will crash, when you are using the PC via Microsoft Remote Desktop. Its a thing... 

Have fun, if you are attempting something similar.


----------



## notimp (May 14, 2020)

Game streaming should be possible via Moonlight, once your are VPNed in. 
https://github.com/moonlight-stream/moonlight-qt/releases


see:
https://old.reddit.com/r/homelab/comments/4yeo3v/gaming_on_remote_desktop/


----------



## notimp (May 14, 2020)

The TomatoFTW reddit is now recommending the Asus RT-AC68U as a used/budget pick, which is in the same price bracket (50-70 USD used). You might want to pick that up instead, if you still need a tomato capable router.

Differences: https://www.mbreviews.com/asus-rt-ac68u-vs-rt-ac66u/

src: (also read this)
https://old.reddit.com/r/TomatoFTW/comments/ftluv8/purchase_advice_budget_used_router_for_qos/


----------



## notimp (May 16, 2020)

Rewrote the Applescript in the first posting to be a bit more feature rich. 

First, the dialog box now also has a cancel button, so you can cancel out of any action (pressing esc works as well).

Second, the wake on lan packets now dont get sent on app start, but once you press either the local or the remote button in the dialog box.

Third, added two curl commands that interface with ifttt.com, which in return interfaces with my Logitech Harmony Hub (if you dont have a universal remote for your TV, buy a Harmony Companion, it comes with a hub, is light weight, lasts longer on a charge (battery) than the Harmonies with LCD screens, and can be found used for around 50 USD...), which switches my TVs HDMI inputs.

If I run the script again, it checks if Synergy is running, and if it is, it switches back to my default HDMI port, and then force quits Synergy. (Thats for when I'm finished, and have already shut down my PC.)

So basically, I run the Applescript (.app), and if I hit local, my TV first switches to the correct HDMI input, then my (Home Theatre) PC gets turned on (WOL), and then it connects to Synergy (allows me to use my Macbook keyboard and Touchpad to control the Windows PC).


[If you are new to IFTTT - you basically have to set up an action where this is 'Webhooks' ( https://ifttt.com/maker_webhooks ) and that is ifttts logitech harmony plugin.

You then give the Webhooks action (on 'this') an event name, and then visit https://ifttt.com/maker_webhooks and click on documentation at the top, then enter the event name to get your activation link. (Action will be triggered whenever the link is loaded.)

In the applescript this is simply implemented with a curl -X POST (link is 'loaded' from the command line, thereby triggering the Harmony hub action of switching HDMI inputs).]


----------



## notimp (Jun 15, 2020)

I've now finished the Android smartphone implementation as well. 

I can now:

Start my Home Theatre PC from my smartphone, from anywhere in the world, open up a VPN connection and then use the Microsoft Remote Desktop App to control it.

Or do that without the VPN connection (because I'm in my home WLAN (= at home  )), or just turn on my PC remotely, and switch to the correct HDMI input on my TV. All from my smartphone. 


To tie everything together, I used automate ( https://play.google.com/store/apps/details?id=com.llamalab.automate&hl=en ) which now basically gives me a list of yes/no questions and then triggers one of the three scenarios above. 

The individual apps used (and settings) might be the more interesting part, but I'll go through the entire process. 
--

Openvpn app used:
https://play.google.com/store/apps/details?id=de.blinkt.openvpn&hl=en

This is not the standard OpenVPN app, but actually my default 'go to app' in all cases OpenVPN.  The reason I used it here is basically, because the default OpenVPN app didnt like my config file above, and I didnt want to have to rewrite it. 

Setup is easy, import the OpenVPN config file (the one with the keys you generated for your android smartphone, because we generated different set of keys for every end device that we wanted to be able to VPN into our router), in the import step also separately show the app where all of your other 3 crt and key files are (its right in the import interface, you basically have to select four files (the config, crt and key files)), and thats it.

Two extra steps in my case were to give the connection a different name in the app, and to deselect 'always show log on connection'. The last one later allows us to automate a VPN connection being established, without the app being opened. (Pulled into the foreground.)
--

Wake on LAN app used:
https://play.google.com/store/apps/details?id=com.bitklog.wolon&hl=en

Its easier to use a dedicated app, than to f.e. install busybox telnet on the android phone and do it via commandline, thats why I went with the app. I couldnt get it to work on my android phone with the most prominent Wake on LAN Android app, but with this one - which is the second most prominent. So yeah. 

For Wake on Lan via LAN, you basically leave out all IPs, and only fill in the MAC address (if I set the broadcast address to 192.168.1.254, it didnt work), the rest you leave at default.

For Wake on Lan via WAN (the internet), you fill in MAC address, your home networks public IP, and the port you specified (different from 9 or 7 in case of local Wake on LAN  - see first posting)

And thats basically it.
--

Remote Desktop App used:
https://play.google.com/store/apps/details?id=com.microsoft.rdc.androidx&hl=en

Setup is almost self explanatory. I stored a user account (so I dont have to log in manually every time). And thats almost it for setup, except, that DNS name translation didnt work when connected over the VPN, so instead of setting the PC up with its 'network name' you type in the (static (router can assign static IPs for every one of your devices dynamically (based on their MAC address), do that in your router) IP address, while setting it up.

Thats it.
--

The rest then is an elaborately stupid Automate workflow:





- without failsaves (if you press cancel at some points it just trucks on, but it doesnt do much, other than opening up apps..  )

Elaborately stupid also because at two points in the graphs I named dialog options yes > no and no > yes, just so I'd have a more pleasant layout on the final textboxes.. 

The workflow basically does the following:

First asks you if you want your PC turned on to pull it up on the TV, or for use with the Microsoft remote Desktop app.

If TV - it tells you which buttons to push on the Wake on lan app (LAN and then your device) for 2 seconds (textbox then auto vanishes), then starts the Wake on lan app, where you press those buttons, then force closes the app after four seconds (root required  ), expecting that you had enough time to do so..  Then it runs one of the curl commands from the first thread to switch to the correct HDMI input on the TV (using ifttt and the Logitech Harmony Hub).

If Remote Desktop - it then asks you "Do you need to connect to a VPN?" -

If yes, it tells you which buttons to push on the Wake on lan app (WAN and then your device) for 2 seconds (textbox then auto vanishes), then starts the Wake on lan app, where you press those buttons, then force closes the app after four seconds (root required  ), expecting that you had enough time to do so..  Then it calls the app shortcut for your VPN connection using your OpenVPN app (that VPNs you into your home router). Then it puts up another textbox (autovanishes after 32 seconds), that tells you - please wait for 30 seconds while your PC boots. And after it vanishes, it opens up the Microsoft Remote Desktop app. (There you then only have to press on your PC and you are connected.)

If no (no VPN needed), it does the same as above (except one textbox reads press on LAN instead of WAN before the Wake on LAN app launches  ) - without the "connect to the VPN" step.

Easy. 

Now I have bragging rights. 

The only thing important to know for the Automate workflow is, that on every yes/no dialog or textbox 'display immediately' has to be ticked during setup. Thats the hardest part, the rest is even easier to find out via trial and error, and the image above..


----------



## leon315 (Jun 15, 2020)

what is wake-up on LAN? is that function which allows me to turn PC on remotely?

Nowdays ALL ISP provide dynamic IP, does this method still work?


----------



## Rusb (Jun 15, 2020)

leon315 said:


> what is wake-up on LAN? is that function which allows me to turn PC on remotely?


Exactly, but unfortunately, in most boards, it only works if the system has been shutdown gracefully, if not, it usually doesn't work.

Although maybe depending on the BIOS are options to solve this.


----------



## notimp (Jun 15, 2020)

leon315 said:


> Nowdays ALL ISP provide dynamic IP, does this method still work?


Thats a step I didn't detail.

For that you need to basically set up DDNS (dynamic DNS) in your router. All open source firmwares support it. Its basically a web service (might even be payed, but usually not expensive..  shop around), that has your router tell the webservice, what its public IP is - at any given time.

The webservice (DDNS) then gives you a static IP address, and forwards that to your real dynamic address. So in the end you now have 'a static public IP adress again' ("ISP provided IP address").

My ISP still asignes me a static IP (changes once every 2-3 years or so..  ) so I didnt have to go through that step.


----------



## Captain_N (Jun 19, 2020)

I never bother with WOL. I just leave the RDP computer on all the time.


----------



## notimp (Jun 19, 2020)

One neat side effect of this, if you add Moonlight to the Automate workflow, you can turn on your PC and start remote streaming to your android device, entirely via your android device.. 

Worlds most elaborate handheld gameing boot sequence..


----------



## notimp (Jul 3, 2020)

While researching around another project, people in the dev communities there mentioned https://www.duckdns.org/ (Amazon cloud hosted) a lot. So this could be a viable starting point, when looking for a DDNS option.

And of course, with the free solutions, you'll probably not get an entire static IP, but just a subdomain (letters and dots instead of numbers and dots). This shouldnt matter though. All WOL solutions should be able to handle a domain as well (not tested.  ).


----------



## notimp (Sep 18, 2020)

Final piece in the puzzle to stream actual games (over LAN and from your PC over the web) is Parsec:
https://parsecgaming.com/

Heard of it first on a Linus Media Group video, where they use it to stream video editing workstations for home office.

Works flawlessly on a Macbook. Set h265 as a codec, dont disable vsync in the app (when doing so, Windows side my mouse vanished). Set the stream bandwidth to 40Mb/s to get a better image quality. Thats about it.

Works flawlessly when set up, allows the GOG client to run (which wouldnt run with Microsoft Remote Desktop). Even resolution changing works on the fly.

And so far, its free. 

And very low latency.


----------



## notimp (Oct 14, 2020)

My Windows 10 Gaming PC in the example had issues shutting down, once I played a game, for about 80% of the time (stuck at shutdown), which kind of threw a spanner into my goal to use this as a remote PC for quite a while. I finally got around to fixing the issue. In case you are experiencing something similar - here is what worked in my case:

1. Disabled fast startup - this was recommended by most sources, but didn't help in my case. In case it does for you:
https://www.windowscentral.com/how-disable-windows-10-fast-startup

One of those two options helped in my case:

2. In Win+R run msconfig, then look at the services tab. Click the checkbox to hide Microsoft services, then try removing some of the ones you dont need. In my case I disabled the Asus Update check, the Asus LightingService, and the Realtech Bluetooth Device Manager, but then forgot to check if that worked.. 

3. What worked more likely was to add the following .bat as a shudown script:

```
@echo OFF
taskkill /IM "Steam.exe" /F
taskkill /IM "GalaxyClient.exe" /F
START "" "C:\Program Files (x86)\IrfanView\i_view32.exe" C:\Users\notimp\Pictures\road.png /one /fs
sleep 0.9
taskkill /IM "pservice.exe" /F
taskkill /IM "parsecd.exe"
:: taskkill /FI "Status eq Not Responding" /F
:: timeout 3
:: shutdown /s /f /t 0
```
First I'm killing off Steam and the GOG client, then I'm doing some entirely uneeded stuff to display a certain image in fullscreen mode using Irfanview (which doesnt visibly execute if the script gets run as a shutdown script (because the Windows 'shutting down' screen overlays it  ), but does, when it gets run manually  ), then I'm killing pservice and parsecd which are the two services Parsec is running.

The lines below that are commented out, and were only used for testing, I leave them in, just in case they help some of you..  (Basically force shutdown of every hanging program, and then force shutdown, once more. (Used when running it as a normal script - when you run it as a shutdown script obviously you dont need to shut down your machine twice.  ).

How to implement a .bat as a shutdown script:
Read this:
https://stackoverflow.com/questions/12434863/executing-a-batch-script-on-windows-shutdown

And then do this:


> Note that, as mentioned in this question, if you want a batch script to run at Logoff, I found referencing the .bat file directly didn't work. However, if I used C:\Windows\System32\cmd.exe as the Script Name and /C C:\path\to\batch\script.bat as the Script Parameters, it did – Nova Oct 8 at 7:19



Now shutting down my gaming rig works every time. You just have to be a bit careful, not to shut the mashine down, while Steam or GOG are still syncing savegames, because again - those programs will be force killed.
--

In addition to that, I rewrote my MacOS Apple script automation (to turn on my remote PC via my Macbook) to also include a check if I want to run Windows Remote Desktop, or Parsec to stream my PC remotely.

Windows Remote Desktop has the advantage, that it auto scales display resolution even to 16:10 resolutions on the client side (Macbook), with Parsec its easier to stick with 16:9 resolutions to use its quick resolution switching. Long story short, Windows Remote Desktop is still better, when working on the Gaming PC, for light workloads (fps afair is limited to 30 or so...).

Because Applescripts only support displaying dialog boxes with a max. of 3 buttons, and one of them has to be cancel, to also make the Esc key work to cancel out of the app, I split the functionality between two apps (both of which open the same dialog window, just with different buttons.  ).

First one (this is what you run, when you want to start the PC).) Save as an .app using Script-Editor on MacOS.

```
set x to isAppLoaded("Synergy")
if x then
    do shell script "curl -X POST https://maker.ifttt.com/trigger/HDMI2/with/key/dedeHDHRBjejjkF8fHBF"
    do shell script "ps aux  |  grep -i Synergy  |  awk '{print $2}'  |  xargs kill -9 & $COMMAND & $EXIT"
else
    display dialog "Local or Remote?" with title "Chose connection method" buttons {"Local", "Remote", "Cancel"} default button "Local" cancel button "Cancel"
    if the button returned of the result is "Remote" then
        do shell script "open -a ~/Documents/FireRemote/remoteDanA4on.app"
    else if the button returned of the result is "Local" then
        do shell script "/usr/local/bin/wakeonlan 192.168.1.254 d4:64:64:64:64:15"
        do shell script "/usr/local/bin/wakeonlan -i 62.100.77.125 -p 26085 d4:64:64:64:64:15"
        do shell script "curl -X POST https://maker.ifttt.com/trigger/HDMI4/with/key/deShldjkmflslksiSDkkfksHBF"
        tell application "Synergy"
            activate
        end tell
    end if
end if

on isAppLoaded(app_name)
    tell application "System Events"
        set app_list to every application process whose name contains app_name
        if the (count of app_list) > 0 then
            return true
        else
            return false
        end if
    end tell
end isAppLoaded
```

First the app checks if Synergy (https://symless.com/synergy) is running on the Macbook, if yes, it switches the TV back to the default HDMI port (in my case HDMI2), using a webhook command to IFTTT, that triggers a Logitech Harmony Hub action. Then it closes Synergy. This is for when I finished a local gaming session - so basically something I want to happen on exit.

If Synergy is not running, I have it display a textbox with three buttons. Local, Remote and Cancel.

When pressing Local, I send a Wake on Lan packet to my LAN and my WAN IP address wo wake the PC up, then I switch my TV to the correct HDMI port (using the IFTTT method described above), then I start Synergy.

When Pressing Remote, I'm launching the second app, which looks like this:

```
display dialog "Local or Remote?" with title "Chose connection method" buttons {"Microsoft", "Parsec", "Cancel"} default button "Microsoft" cancel button "Cancel"
if the button returned of the result is "Microsoft" then
    do shell script "/usr/local/bin/wakeonlan 192.168.1.254 d4:64:64:64:64:15"
    do shell script "/usr/local/bin/wakeonlan -i 62.178.47.134 -p 26085 d4:64:64:64:64:15"
    delay 37
    tell application "Microsoft Remote Desktop"
        activate
    end tell
else if the button returned of the result is "Parsec" then
    do shell script "/usr/local/bin/wakeonlan 192.168.1.254 d4:5d:64:53:96:15"
    do shell script "/usr/local/bin/wakeonlan -i 62.100.35.150 -p 26085 d4:5d:64:53:96:15"
    delay 35
    do shell script "ps aux  |  grep -i Parsec  |  awk '{print $2}'  |  xargs kill -9 & $COMMAND & $EXIT"
    delay 2
    do shell script "/Applications/Parsec.app/Contents/MacOS/parsecd peer_id=1iagwxOfroddmfksnkllsdwyxQzB"
end if
```
This displays a dialog with three buttons: Microsoft, Parsec and Cancel

When pressing Microsoft, I send Wake on LAN packets to my LAN and WAN addresses to wake the PC up, then wait 37 seconds (for my PC to boot), then open Microsoft Remote Desktop.

When pressing Parsec, I send Wake on LAN packets to my LAN and WAN addresses to wake the PC up, then wait 35 seconds (for my PC to boot), then kill Parsec locally on the Mac (if running), then wait 2 seconds and start it again with the command line argument to automatically connect it to my gaming PC.

For help how to do this using Parsec, read this:
https://support.parsecgaming.com/hc...ication-On-Your-Computer-Via-The-Command-Line

Thats it, I used this multiple times over the past days to game on my Macbook (Game streamed from the Windows PC via Parsec), and it works as intended.

I had fun. 

PS: I garbled all ip addresses and keys in the script for privacy reasons before posting.


----------

