Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python code to automate desktop activities in windows

I want to automate desktop activities in Windows environment using Python. How it can be done? Some examples will also be helpful.

By desktop activities, I mean actions such as taking control over mouse and keyboard, access active windows properties, double-click on an icon on the desktop, minimize and maximize windows, enter data to an input popup window through keyboard, etc.

like image 774
stallion Avatar asked Aug 06 '12 09:08

stallion


People also ask

How do I automate a desktop application in Python?

Steps to tackle this task,Install python and then pywinauto + pytest in your python environment (preferably in your own virtualenv) Launch your desktop app. Launch SWAPY and look at the list of apps it displays, watch for your app in that list.

Can you use Python to automate Windows?

pywinauto is a set of python modules to automate the Microsoft Windows GUI. At its simplest it allows you to send mouse and keyboard actions to windows dialogs and controls, but it has support for more complex actions like getting text data.

Can I use Python to automate tasks?

Python is a versatile language that can be used for various automation tasks. You can use Python for automating file or folder management, generating reports from data stored in a database, monitoring logs on your servers, creating website scrapers, among other things.


2 Answers

Have a look at SIKULI.

Sikuli is a visual technology to automate and test graphical user interfaces (GUI) using images (screenshots).

SIKULI uses a very clever combination of taking screenshots, and embedding them into your python (it's jython, actually) script.


Take screenshots:

enter image description here

and use them in your code:

enter image description here

like image 186
sloth Avatar answered Sep 26 '22 02:09

sloth


You can try Automa.

It's a Windows GUI automation tool written in Python which is very simple to use. For example, you can do the following:

# to double click on an icon on the desktop doubleclick("Recycle Bin")  # to maximize click("Maximize")  # to input some text and press ENTER write("Some text", into="Label of the text field") press(ENTER) 

The full list of available commands can be found here.

Disclaimer: I'm one of Automa's developers.

like image 33
Tytus Avatar answered Sep 26 '22 02:09

Tytus