DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,673 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for houry: A Simple Python App That Beeps Every Hour
Sergey
Sergey

Posted on

houry: A Simple Python App That Beeps Every Hour

A few years ago, in the β€˜pre-Apple-Watch’ era, I had a Casio F-91W. It was a very cheap watch, but it had a nice feature. There was a special setting that allowed it to beep every hour. And that was amazing! It was like a special notification for me to notice the moment.

Every time I heard a beep, I wondered if the thing I was doing was distracting me or helping me? In other words, that beep was very useful to me.

But then I bought the Apple Watch and the magic disappeared. I tried to find an app on my phone or laptop that would beep every hour, but could not.

So let's bring the magic back! I am going to use Python to create a little app for my computer with OS X that will make a sound every hour. Let’s go!

First, we need to teach our app to understand the time and play a sound. Google says these libraries should help with that:

import schedule
import time
from playsound import playsound
Enter fullscreen mode Exit fullscreen mode

Now let’s find the sound. Go to Soundjay and choose something you like. I chose this beep-sound and saved it to my project folder.

def beep():
    playsound('/beep.wav')
Enter fullscreen mode Exit fullscreen mode

Now let’s play it every hour at 00 minutes:

schedule.every().hour.at(":00").do(beep)
Enter fullscreen mode Exit fullscreen mode

And as the documentation says, I should add this to make a loop:

while True:
    schedule.run_pending()
    time.sleep(1)
Enter fullscreen mode Exit fullscreen mode

Let’s try it. Everything works fine.

Now I want to make it a standalone app for my Mac. But I don’t like it to show up in the dock or menu bar. I just want it to run in the background, so here are some magic words for the setup.py file:

from setuptools import setup

APP = ['houry.py']
DATA_FILES = []
OPTIONS = {
    'argv_emulation': True,
    'iconfile': 'icon.icns',
    'plist': {
        'CFBundleShortVersionString': '0.2.0',
        'LSUIElement': True,
    },
}

setup(
    app=APP,
    data_files=['beep.wav'],
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)
Enter fullscreen mode Exit fullscreen mode

As you can see, I created an icon for this app. Yes, you will only see it when you run this app, but I still wanted it to look nice. So I just took an emoji from Emojipedia, converted it via Anyconv, and saved it in the main folder of my project.

And the last step. To create an app, we should type this in the Terminal:

python setup.py py2app
Enter fullscreen mode Exit fullscreen mode

That’s it. Now you can find your app in the β€˜dist’ folder. Do not forget to move it to the β€˜Application’ folder and add it to Login Options on your Mac.

Happy houry!

Project on GitHub β†’

Top comments (3)

Collapse
 
nskeip profile image
Nikita Hismatov

It would be nice to have requirements listed inside of setup.py (check out the setup function parameters), so users can have the script up and running without pip install -r requirements.txt.

Collapse
 
skaplichniy profile image
Sergey Author

Thanks, Nikita! I will add it soon

Collapse
 
ssbozy profile image
Sandilya Bhamidipati

Thanks for the nice write up.

Search No More

Join DEV and MongoDB and build an application with full-text search capabilities using MongoDB Atlas and Atlas Search for the DEV x MongoDB Atlas Hackathon 2022.

β†’ Join the Hackathon