r/Python • • Aug 17 '26

Discussion What are some Python automations you built for your life?

What Python scripts/projects did you built to use on a day to day basis? Or maybe someone else built it, but it’s useful for your personal life in some way

I think the “projects ideas” thread is really missing those useful opportunities

I myself thought about automating tax calculations, but still didn’t take the time to do it hah

323 Upvotes

164 comments sorted by

View all comments

Show parent comment

2

u/Mysterious_Cow123 Aug 20 '26

Hi, python neophyte here.

Does this send a keyboard signal as "F13" -- which i assume is a macro you've set up?

The time.sleep is confusing. Is this putting the keyboard to sleep until you press the F13 key or waiting 30 seconds hitting F13, waiting 30 seconds hitting F13, over and over until you force stop it?

2

u/pacopac25 Aug 20 '26 edited Aug 20 '26

No it's putting your program to sleep. It's basically saying "send F13, then do nothing for 30 seconds, then send F13 again, for as long as True is True" A forever loop, since True is always True.

F13 does nothing on most systems, I don't have an F13 key so it's just a keypress that doesn't input anything.

You could enclose it in a try: and then except KeyboardInterrupt which would allow you to cleanly terminate it with CTRL-C. Add some other niceties:

import sys, keyboard, time

timeout = int(sys.argv[1]) if len(sys.argv) > 1 else sys.exit("Usage: ih8teams.py <timeout>")

while True:
  try:
    keyboard.send("F13")
    time.sleep(timeout)
  except KeyboardInterrupt:
    exit()

1

u/Mysterious_Cow123 Aug 20 '26

I see. Thank you for explaining!

But what utility does this serve? (Or where you being sarcastic and I missed the joke?)

3

u/pacopac25 Aug 20 '26

In the post by tuco86, sending a periodic key-press is a way to keep your status as Active in corporate messaging (Or VagueWare as in the case of MS Teams), so sending nothing every so often keeps your status as "green".

However, the keyboard module has some more interesting features. You can create your own macros. I use this to substitute my work email, which is long, when I type "@@" and space.

from keyboard import add_abbreviation as abbr

abbr("@@", "mylongcompany.email@longcompanyname.com")
abbr("!@", "mylongcompanystreetaddress")

keyboard.block_key("num lock") # I hit numlock by accident a lot

# This listens for Fn + F12 to close the script
keyboard.wait("browser favorites") 

1

u/Mysterious_Cow123 Aug 22 '26

Ohh! That makes so much more sense.

And cool feature. Thanks for the explainer !

1

u/gabriel_GAGRA Aug 31 '26

I did this too! But I used .ps1 script with Auto HotKey and put it to windows startup, it changes @@ and other variations

I’m not sure the reason I chose it at the time, but it’s probably more efficient than running with Python though