๐Ÿ Useful Automation with Python and winshell: 5 ideas to improve your productivity on Windows

  


The winshell library is a little gem for developers on Windows systems. It allows you to automate several common and tedious tasks such as interacting with the Recycle Bin, managing shortcuts, cleaning temporary folders, and navigating special system paths such as the Desktop and Start Menu.

In this article, we'll see 5 concrete and automatable uses with practical examples to improve system management and productivity with Python.

๐Ÿ”— Do you like Techelopment? Check out the site for all the details!

๐Ÿ”ง Requirements

Install the library with:

pip install winshell

⚠️ Works only on Windows, with Python 3.5 or higher.


1. ๐Ÿงน Automatically empty the Windows Recycle Bin

Why is it useful?

Over time, the Recycle Bin can accumulate gigabytes of junk files. Automating its cleanup allows you to keep your system leaner and tidier.

Python Code:

import winshell

# Empty the trash without confirmation and with a completion sound
winshell.recycle_bin().empty(
confirm=False, # No confirmation dialog
show_progress=False, # Do not show the progress bar
sound=True # Play a "ding" sound when finished
)

2. ๐Ÿ”– Create Desktop Shortcuts

Why is it useful?

Automating the creation of shortcuts can be very useful for:

  • distributing Python scripts with a desktop icon
  • creating initial setups for work environments
  • configuring shortcuts to internal tools

Python Code:

import winshell

# Get the current user's desktop path
desktop = winshell.desktop()

# Create the "Notepad.lnk" shortcut on the desktop
shortcut_path = f"{desktop}\\Notepad.lnk"
shortcut = winshell.shortcut(shortcut_path)

# Define the executable path and write the link
shortcut.path = r"C:\Windows\System32\notepad.exe"
shortcut.write()

print("Shortcut created successfully!")

3. ๐Ÿ—‚️ Navigate through special Windows paths (Desktop, Start Menu, etc.)

Why is it useful?

Windows uses many "special" folders (Desktop, Start Menu, AppData, etc.) that can vary depending on the user. With winshell you can securely and dynamically access these directories, without hardcoding the paths.

Practical example:

import winshell

print("Desktop:", winshell.desktop())
print("Start Menu:", winshell.start_menu())
print("Documents:", winshell.my_documents())
print("Temp folder:", winshell.temp())

Possible uses:

  • scripts that search for files on the desktop

  • automatic saves in docsincrements

  • Installing Start Menu Shortcuts

  • Cleaning the Temporary Folder


4. ๐Ÿงผ Automatically clean up user temporary files

Why is it useful?

Temporary files accumulate over time and take up space. Automating their elimination is a light but useful form of system maintenance.

Code to move files to trash:

import os
import winshell

# Get the user's Temp folder
temp_dir = winshell.temp()

# Scan and move files to trash
for file in os.listdir(temp_dir): 
file_path = os.path.join(temp_dir, file) 
try: 
if os.path.isfile(file_path): 
winshell.delete_file(file_path, send_to_recycle=True) 
print(f"Sent to trash: {file}") 
except Exception as e: 
print(f"Error on {file}: {e}")

5. ๐Ÿ”Ž Search for specific files on the Desktop

Why is it useful?

Ever forget where you saved that .pdf or .xlsx file? A Desktop search script can help you quickly find files by type, name, or date.

Example: Search for all .pdf files on the Desktop

import os
import winshell

desktop = winshell.desktop()
extension = ".pdf"

print(f"Files with extension {extension} found on the Desktop:\n")

for filename in os.listdir(desktop):
filepath = os.path.join(desktop, filename)
if os.path.isfile(filepath) and filename.lower().endswith(extension):
print("-", filename)

Possible extensions to search for:

  • .txt for notes
  • .jpg or .png for images
  • .py for Python scripts
  • .docx for documents

You can also extend the script to sort files by date, copy them elsewhere, or list them in a GUI.


๐Ÿ”š Conclusion

The winshell library offers simple yet powerful tools for:

FeatureUsage
๐Ÿงน Empty Recycle BinAutomatic Maintenance
๐Ÿ”– ShortcutsSmart Shortcuts
๐Ÿ—‚️ Special PathsScripts Compatible with Every User
๐Ÿงผ Temp File CleanupSystem Lightness
๐Ÿ”Ž File SearchPersonal Productivity

With just a few scripts, you can simplify your life, keep your PC clean, and save time.



Follow me #techelopment

Official site: www.techelopment.it
facebook: Techelopment
instagram: @techelopment
X: techelopment
Bluesky: @techelopment
telegram: @techelopment_channel
whatsapp: Techelopment
youtube: @techelopment