@
luoway mac 上能用的
```
#!/usr/bin/env bash
cd /tmp
# Create the source file
cat > main.m << EOF
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
int main () {
NSBundle *bundle = [NSBundle bundleWithPath:@"/Applications/Utilities/Keychain
Access.app/Contents/Resources/Keychain.menu"];
Class principalClass = [bundle principalClass];
id instance = [[principalClass alloc] init];
[instance performSelector:@selector(_lockScreenMenuHit:) withObject:nil];
return 0;
}
EOF
# Compile the source file
clang -framework Foundation main.m -o lockscreen
```
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import Foundation
import objc
import AppKit
import sys
import os
import threading
import functools
import time
NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
def notify(title, subtitle, info_text, delay=0, sound=False, userInfo={}):
notification = NSUserNotification.alloc().init()
notification.setTitle_(title)
notification.setSubtitle_(subtitle)
notification.setInformativeText_(info_text)
notification.setUserInfo_(userInfo)
if sound:
notification.setSoundName_("NSUserNotificationDefaultSoundName")
notification.setDeliveryDate_(Foundation.NSDate.dateWithTimeInterval_sinceDate_(delay,
Foundation.NSDate.date()))
NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
time.sleep(5)
curr_path = os.path.dirname(os.path.abspath(__file__))
os.system("{}/lockscreen".format(curr_path))
def work_fn():
notify(title="STOP!!!!!!!!!!", subtitle="take a rest", info_text="AAAAAAAAAAAAAAAAAAAAAAAAA", sound=True)
def main():
work_fn()
if __name__ == '__main__':
main()
```
然后丢到 launchctl 一小时跑一次这个 python 脚本