Created
November 3, 2018 21:46
-
-
Save ihaveamac/da97c457a1f5410995a27671b83b8691 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from datetime import datetime | |
from os import stat | |
from sys import argv, exit | |
from shutil import copy2 | |
from Foundation import NSUserNotification | |
from Foundation import NSUserNotificationCenter | |
from Foundation import NSUserNotificationDefaultSoundName | |
def notify(_title, _message, _sound = False): | |
notification = NSUserNotification.alloc().init() | |
notification.setTitle_(_title) | |
notification.setInformativeText_(_message) | |
if _sound == True: | |
notification.setSoundName_(NSUserNotificationDefaultSoundName) | |
center = NSUserNotificationCenter.defaultUserNotificationCenter() | |
center.deliverNotification_(notification) | |
main = '/Users/ianburgwin/Library/Mobile Documents/com~apple~CloudDocs/keepass/Passwordthings.kdbx' | |
win_copy = '/Volumes/Things/keepass-windows/Passwordthings.kdbx' | |
if len(argv) < 2: | |
exit(f'{argv[0]} <to-win/to-mac>') | |
if argv[1] == 'to-win': | |
copy2(main, win_copy) | |
print(f'{datetime.now().strftime("%H:%M:%S")} - Copied {main} to {win_copy}') | |
elif argv[1] == 'to-mac': | |
c_mac = int(stat(main).st_mtime) | |
c_win = int(stat(win_copy).st_mtime) | |
if c_mac != c_win: | |
if c_mac > c_win: | |
msg = 'Mac copy is newer.' | |
else: | |
msg = 'Windows copy is newer.' | |
print('Showing notification about mismatched times.') | |
notify('KeePass database time mismatch', msg) | |
# copy2(win_copy, main) | |
# print(f'Copied {win_copy} to {main}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment