Send command trough Windows Batch (If Itunes started, start Audio)

Hi all,
I created a new shortcut for my Audio system. If i launch the itunes shortcut, a batch starts, which will will power on my speaker via cURL/the REST interface of OH and then start itunes.

On windows you need to install cygwin and within cygwin please install cURL.

create a batch script (itunes.bat)
Place the following in your batch: (On a x86 machine the path might be different)

@echo OFF
ping -n 1 172.20.0.1
if errorlevel 1 goto iTunes
if errorlevel 0 goto cURL
:cURL
c:\cygwin64\bin\bash.exe --login -i -c 'curl --header "Content-Type: text/plain" --request POST --data "ON" http://user:password@172.20.0.1:8080/rest/items/AUDIO'
:iTunes
start "" "C:\Program Files\iTunes\iTunes.exe"
exit

You’ll need to replace the target of your itunes shortcut with your batch.
Set the shortcut to start minimized, so you won’t notice the cmd window.

EDIT: Added Ping check before sending data to the OH-Server (if your Laptop is not at home, don’t send a command, that wouldn’t be transfered)

1 Like

Just a note, you can get just cURL for Windows if you don’t want/need cygwin. It is a portable binary so you can just drop it into your path.

Thanks for your advice.

I know that it is possible to use cURL on Windows without Cygwin.
It might be more complicated to install things trough cygwin.
But i want to use cygwin, in case i need other services within cygwin.

Agreed. Cygwin is often the first thing I install on my Windows machines. I just wanted to let future readers of this thread know that they can just get cURL by itself for Windows if they don’t want the full cygwin.

1 Like