macOS Python automated time management script

In macOS, there is another function called calendar. My calendar is always full, but I have never implemented it seriously. So I was thinking how could there be a way to force me to do something seriously?

My calendar schedule

 

Later, I thought of a way to write an automated script to automatically open DingTalk when class was about to start, and put the computer to sleep after class.

Ideas

At first I wanted to use "Automatic Actions" in macOS to force one thing.

automatic operation
automatic operation

 But the operations in the automatic operation cannot be started and executed regularly, so I thought of another plan.

Use Python to loop, and if the time is equal to a certain moment, start the automatic operation APP written by "Automatic Operation" to force the execution of the task.

Start doing it

Writing "Automatic Actions"

First, write an automatic operation called "Teaching Class".

Turn on automation

Create a new application

This is what I wrote inside

What I wrote was to open DingTalk, turn up the volume, and speak to remind me.

Then write the get out of class automation

I wrote like this

 Write Python automation scripts

The main idea of ​​the Python script is an infinite loop, in which the detection time is written. If the time is detected to be equal to something, automation is started.

I won’t write the process, just put the code directly.

Note: I have written several other automations here, but they involve privacy such as user passwords, so I have deleted them here.

import time,os

"""
我把这个文件命名为date.py 所在目录名为xxx
这里我把两个下课、上课等自动化放在了“/Users/Petyr/Applications/”
我这里写了其他的几个自动化,但是涉及用户密码等隐私,在这里删掉了
"""

while True:
	if(time.strftime("%H:%M",time.localtime())=="08:25"): 
		os.system("open /Users/Petyr/Applications/上课.app")# 打开“下课”自动化
		time.sleep(50)
	if(time.strftime("%H:%M",time.localtime())=="18:00"):
		os.system("open /Users/Petyr/Applications/下课.app")# 打开“下课”自动化
        time.sleep(50)
	time.sleep(5)

Finally, package it into an application

cd xxx
pip install pyinstaller
pyinstaller -F -w date.py

Then set it to auto-start

 

The supervision effect is quite good. The main reason is that I wrote it myself. I am very happy and have a sense of accomplishment when executing it.

おすすめ

転載: blog.csdn.net/m0_64848283/article/details/128452870
おすすめ