Windows PC macro

I know this is more of a computer programming question, that an Arduino programming question, but I thought you guys and girls might know the answer.

I am basically using An Arduino, Connect to it via a USB to a Windows laptop. I am using a third party application on iPhone called Blynk. This application connects via the Internet to control the Arduino.

To connect the Arduino to the Internet, it has to be hardwired with the USB, and then I have to open the command prompt, change the directory to the scripts folder, and then run one of the scripts contained within it to initialise the com port that the Arduino is on.

If however, the Arduino is disconnected, The connection drops, and I have to go through the command prompt sequence again.

Now on my Mac book, you can create a macro or widget and easily record the steps but you have to take, and it will create a single button that will play the steps when you click it. In other words on a MacBook I can double-click an icon, and it would do the connection script in one go. Is there a way of doing that in Windows?

Google 'Windows batch file'
Depending on what is required, also Google 'Windows Powershell'

Arrr that looks like it would work.

It's basically this...

Open CMD prompt
Paste a line of text
Paste another line of text

You don't need to worry about any of that if you use a batch file. It's difficult to give you specifics because you didn't provide details but here's an example of a batch file:

cd /d c:\foo\scripts

Here's what it does:

  • Change the current directory to c:\foo\scripts
  • run an executable file named somescript

Here's an easy way to make a batch file:

  • Decide on a convenient location on your computer to store the batch file and open that folder in Windows Explorer
  • Right click in the folder and select "New > Text Document"
  • Open the new text document
  • Add the commands you want the batch file to run.
  • Save and close the file.
  • Right click on the text file and select "Rename"
  • Give the file a convenient name and the .bat extension. Note that by default Windows hides extensions from you so you need to make sure the file is actually named e.g. foo.bat, not foo.bat.txt.
  • Now by double clicking on the batch file the commands it contains will be executed.
  • (Optional) Right click on the batch file and select "Send to > Desktop (create shortcut)". You can leave this shortcut on your desktop or move it to the start menu to make it more convenient to run the batch file.

When you run the batch file it opens a command line window, runs the commands, then closes the window. This can make it difficult to see what is going on for troubleshooting. The solution is to add the line:


at the end of the batch file. That will require to to press a key to close the command line window.

If you want to make the batch file even easier to run you can assign a shortcut key to the batch file's shortcut. This is an option in the Right Click > Properties menu.