Automating Desktop Applications with Python
This tutorial follows on from last week’s automating web browsers with Python. If you have not seen that one yet, you can check it out at the following link:
The same as last week, I’m going to be using Visual Studio to write the program, but you can use any text editor of your choosing. Just remember to say the file with the .py extension, so that your machine will run it as a Python executable.
To begin with, we need to import the ‘os module’. The module gives access to Operating System functionality and allows the opening of programs.
Once the ‘import os’ command has been written, there is only one more command left to write and that is ‘os.system(‘start <application_name>’)
This command can be written as many times as needed, just by changing the application name to something different.
In the end, this program was relatively simple to write. However, it did cause my quite a bit of frustration trying to figure out the syntax needed for the program to run correctly. I have added the code from this program to what I wrote last week to setup an automated link on my desktop, so that it will run with a double-click of the mouse.
This can be expanded on further still by allowing the newly created application to run on start-up.
In the bottom left-hand corner of your keyboard near the ‘ctrl’ key, should be ‘Windows flag’ also known as the ‘Super-user key’ in Linux. Press the Windows Key and the letter ‘R’ at the same time. This will open a tab called ‘run’.
In the window that opens, copy and paste the newly saved Python program to that location. This should then run every time the machine is booted up.
To stop the file from running at start up, delete the file from that location. Alternatively, open Task Manager using Ctrl + Alt + Delete and navigate to the ‘Start-up’ items. The program should be listed, right-click on the item to enable or disable it.
Finally, save all your work and reboot the machine to test it works when the machine boots up.
Congratulations, you have just created your first automated setup using Python Programming.