-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thyme, restart timer on login . Option request. #47
Comments
It took some time, but i made a script on python for this, it's like a workaround for this issue. Hope it will be fixed) #!/usr/bin/python
import Quartz
import datetime
import subprocess
def do_func_on_lock_or_unlock(unlock_f=None, lock_f=None):
# """This function will continiously monitor if your screen is locked or unlocked
# On action(lock/unlock) it can execute any given function, which you can pass as parameter to this function"""
def check_if_unlocked(past_lock_status, current_lock_status):
return past_lock_status == True and current_lock_status == False
def check_if_locked(past_lock_status, current_lock_status):
return past_lock_status == False and current_lock_status == True
print 'Currently screen is unlocked(should be), we will send you any updates!'
mem = False
unlock_time = datetime.datetime.now().replace(microsecond=0)
while 1:
d = Quartz.CGSessionCopyCurrentDictionary()
lock_status = 'CGSSessionScreenIsLocked' in d.keys()
if check_if_locked(mem, lock_status):
mem = lock_status
print 'Screen was locked'
# lock_time = time.ctime(d['CGSSessionScreenLockedTime'])
lock_time = datetime.datetime.now().replace(microsecond=0)
time_diff = lock_time - unlock_time
print 'You was working for ' + str(time_diff)
if callable(lock_f):
lock_f()
if check_if_unlocked(mem, lock_status):
mem = lock_status
print 'Screen was unlocked'
unlock_time = datetime.datetime.now().replace(microsecond=0)
time_diff = unlock_time - lock_time
print 'You was absent for ' + str(time_diff)
# print unlock_time
# print d['CGSSessionScreenLockedTime']
if callable(unlock_f):
unlock_f()
def asrun(ascript):
ascript = """tell application "Thyme"
stop
start
end tell"""
# "Run the given AppleScript and return the standard output and error."
osa = subprocess.Popen(['osascript', '-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
return osa.communicate(ascript)[0]
script = """tell application "Thyme"
stop
start
end tell"""
def thyme():
asrun(script)
do_func_on_lock_or_unlock(thyme) |
Also, If you save it as Automator Application (choose Run bash script, choose python) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I know you are not working on this project anymore, but, it would be great to add feature to restart timer every time you login to your mac.
It is great feature when you need to track your time sitting in front of your mac. You can see on timer, if time goes above 50min - you should make some movement)
I am sure it's not a big deal to add such option, so, I hope someone will add it.
The text was updated successfully, but these errors were encountered: