Mac脚本 定时气泡提醒休息

Posted by kifish on April 27, 2018

python toy.py

import os
from time import sleep
#os.system('osascript -e 'display notification "通知内容" with title "标题" subtitle "子标题"'') #error
#python 引号嵌套,这里要用三引号
"""
os.system('''
            osascript -e 'display notification "通知内容" with title "标题" subtitle "子标题"'
          ''')


succeed!
"""

cmd = '''
         osascript -e 'display notification ":)" with title "出去走走" subtitle "休息" '
      '''

while True:
    sleep(3600)
    os.system(cmd)
    sleep(5)
    os.system(cmd)








'''
import notify2
notify2.init("first bubble app@mac")
my_bubble_notify = notify2.Notification("Summary",
                         "Some body text",
                         "notification-message-im"   # Icon name
)
my_bubble_notify.show()


Traceback (most recent call last):
  File "/Users/k/Documents/python_prac/test3.py", line 1, in <module>
    import notify2
  File "/Users/k/anaconda3/lib/python3.6/site-packages/notify2.py", line 39, in <module>
    import dbus
ModuleNotFoundError: No module named 'dbus'
kdeMacBook-Pro:paper_author_process k$ pip install dbus
Collecting dbus
  Could not find a version that satisfies the requirement dbus (from versions: )
No matching distribution found for dbus
'''

'''
import pynotify
pynotify.init("first bubble app@mac")
my_bubble_notify = pynotify.Notification("Mac上的泡泡提示","站起来走走")
#my_bubble_notify = pynotify.Notification ("Hello DL","欢迎.....自我吹捧一下。 <a href="http://www.baidu.com">点此到百度</a>")
my_bubble_notify.show()

AttributeError: module 'pynotify' has no attribute 'init'
因为有人也写了个pynotify,这个包是用来发邮件的。安装错了

'''



win10:

import os,sys,time,subprocess
from datetime import datetime
from tkinter import messagebox

if len(sys.argv) == 1:
    msg = input("待做的事:\n")
    t = input('定时, h:m:s\n')
    hms = t.split(':') if '.' in t else t.split(':')
    h,m,s = hms
    h = 0 if int(h) >= 24 else int(h)
    m,s = min(int(m),59),min(int(s),59)

    now = datetime.now()
    count = (h - now.hour)*3600 + (m-now.minute)*60 + (s-now.second)
    subprocess.Popen(['pythonw',__file__,msg,str(count)])

else:
    time.sleep(int(sys.argv[2]))
    messagebox.showinfo("时间到了!",sys.argv[1])