01-15-2023, 12:14 PM
How I used Python to Automate my Daily Routine with Desktop Notifications
Rate this post
![[Image: pexels-meruyert-gonullu-6589149-683x1024.jpg]](https://blog.finxter.com/wp-content/uploads/2023/01/pexels-meruyert-gonullu-6589149-683x1024.jpg)
[b]Project Description[/b]
Today while working on my Python code, I suddenly realized that it’s been two hours since I have been trying to solve the bug. I was constantly looking at the screen for two hours without even realizing to take a break or drink a glass drink water. That is when I thought of creating a script that would automate my daily routine with desktop notifications. I thought of creating a script that will generate a notification after certain time intervals for the following:
Therefore, in this project, we will be learning how to automate the daily routine using desktop popup notifications. So, without further delay, let’s dive into the steps to complete our project.
[b]Step 1: Install and Import the Necessary Libraries[/b]
The two important libraries we need in this project are and . The module is used to create the desktop notifications. It notifies us when any event occurs. Since it is not a built-in Python library, therefore you need to install it using PIP. Open your terminal and type the following command –
Once you have installed the win10toast module, go ahead and install the library as follows:
Library helps us to schedule a task at a particular time every day or even on a particular day. It matches our system’s time to the scheduled time set and then calls the function. You will also need the help of the module while scheduling the tasks. So, make sure that you also import the module in your script.
[b]Step 2: Creating Notifications[/b]
I used the ToastNotifier class from the module to create an object and the method to create a notification. The following code will generate a notification that will stay on the screen for 10 seconds.
Explanation: The first argument in the method is the header of the notification and the second argument is the message that you want to display within the notification window. The duration (mentioned in seconds) specifies how long the notification will remain on the desktop screen before disappearing.
[b]Step 3: Scheduling the Tasks[/b]
Code:
Explanation: As we need to generate the notifications after certain time intervals we would use the module that will schedule the tasks as per the given/required intervals. We will also use the method from the module, to let the next line of code execute after some time specified in seconds.
[b]Step 4: Creating the Task Functions[/b]
Next, I created different functions that will perform different tasks when called. The function to remind me to:
[b]Putting it All Together[/b]
Now let’s put it all together to visualize how the entire script works :
[b]Conclusion[/b]
There we go! We have successfully created a wonderful automated script that will generate notifications for us, giving us prompts at certain intervals to organize our work and daily routine. I hope this project added some value and helped you in your coding quest. Stay tuned and subscribe for more interesting projects and tutorials.
Do you love automating tasks with Python? Well! I do. And if you are someone who likes automation then here’s a list of few mini projects that will get you going –
Rate this post
![[Image: pexels-meruyert-gonullu-6589149-683x1024.jpg]](https://blog.finxter.com/wp-content/uploads/2023/01/pexels-meruyert-gonullu-6589149-683x1024.jpg)
[b]Project Description[/b]
Today while working on my Python code, I suddenly realized that it’s been two hours since I have been trying to solve the bug. I was constantly looking at the screen for two hours without even realizing to take a break or drink a glass drink water. That is when I thought of creating a script that would automate my daily routine with desktop notifications. I thought of creating a script that will generate a notification after certain time intervals for the following:
- Drink 1 glass of water ( notify after every 1 hr)
- Take a break from work (after every 1 hr )
- Restart work ( after 10 mins of 2nd notification)
- Medicine Notification at 10 PM every day
- Take backup and end work ( at 8 PM ) every day
Therefore, in this project, we will be learning how to automate the daily routine using desktop popup notifications. So, without further delay, let’s dive into the steps to complete our project.
[b]Step 1: Install and Import the Necessary Libraries[/b]
The two important libraries we need in this project are
Code:
win10toastCode:
scheduleCode:
win10toastCode:
pip install win10toastOnce you have installed the win10toast module, go ahead and install the
Code:
scheduleCode:
pip install scheduleCode:
ScheduleCode:
commandCode:
timeCode:
timeCode:
import win10toast
import schedule import timeI used the ToastNotifier class from the
Code:
win10toastCode:
show_toastCode:
noti = win10toast.ToastNotifier()
noti.show_toast("Demo", "You will get a notification", duration = 10)Explanation: The first argument in the
Code:
show_toast[b]Step 3: Scheduling the Tasks[/b]
Code:
Code:
schedule.every().hour.do(water)
schedule.every().hour.do(take_break)
schedule.every(10).to(15).minutes.do(work)
schedule.every().day.at("22:00").do(medicine)
schedule.every().day.at("20:00").do(backup)
while True: schedule.run_pending() time.sleep(1)Explanation: As we need to generate the notifications after certain time intervals we would use the
Code:
scheduleCode:
sleepCode:
time[b]Step 4: Creating the Task Functions[/b]
Next, I created different functions that will perform different tasks when called. The function to remind me to:
- Drink a glass of water every 1 hour is as follows:
Code:
def water(): noti.show_toast('Time to drink water!', duration= 10)- Take a break from work (after every 1 hr )
Code:
def take_break(): noti.show_toast('You have been working since one hour. Time to take a break', duration= 10)- Restart work ( after 10 mins of 2nd notification)
Code:
def work(): noti.show_toast('Restart your work', duration= 10)- Medicine Notification at 10 PM every day
Code:
def medicine(): noti.show_toast('Time to take the medicine', duration= 15)- Take backup and end work ( at 8 PM ) every day
Code:
def backup(): noti.show_toast('Take backup and end work', duration= 15)Now let’s put it all together to visualize how the entire script works :
Code:
import win10toast
import schedule import time noti = win10toast.ToastNotifier() def water(): noti.show_toast('Time to drink water!', duration= 10) def take_break(): noti.show_toast('You have been working since one hour. Time to take a break', duration= 10) def work(): noti.show_toast('Restart your work', duration= 10) def medicine(): noti.show_toast('Time to take the medicine', duration= 15) def backup(): noti.show_toast('Take backup and end work', duration= 15) schedule.every().hour.do(water)
schedule.every().hour.do(take_break)
schedule.every(10).to(15).minutes.do(work)
schedule.every().day.at("22:00").do(medicine)
schedule.every().day.at("20:00").do(backup) while True: schedule.run_pending() time.sleep(1)There we go! We have successfully created a wonderful automated script that will generate notifications for us, giving us prompts at certain intervals to organize our work and daily routine. I hope this project added some value and helped you in your coding quest. Stay tuned and subscribe for more interesting projects and tutorials.
Do you love automating tasks with Python? Well! I do. And if you are someone who likes automation then here’s a list of few mini projects that will get you going –
- Create Your Own YouTube Video Downloader
- The Power of Automation Using Python – Segregating Images Based on Dimensions
- Automate Backup to Google Drive with Python
- Receive Automated Email Notification on Website Update
- The Art of Automating Whatsapp Messages Using Python
- Create Your Own YouTube Video Downloader

