first commit
This commit is contained in:
63
app/util/system_api.py
Executable file
63
app/util/system_api.py
Executable file
@@ -0,0 +1,63 @@
|
||||
from app.util.shell_execute import execute
|
||||
from app.util.apple_script import AppleScript
|
||||
import Quartz
|
||||
from app.config import Config
|
||||
import time
|
||||
|
||||
def open_url(url, new=False, wait=False, bundle: str = None, p_args=None):
|
||||
args = ['/usr/bin/open']
|
||||
if new:
|
||||
args.append('-n')
|
||||
if wait:
|
||||
args.append('-W')
|
||||
if bundle:
|
||||
args.append('-b')
|
||||
args.append(bundle)
|
||||
|
||||
args.append(url)
|
||||
|
||||
if p_args is not None:
|
||||
args.append('--args')
|
||||
for arg in p_args:
|
||||
args.append(arg)
|
||||
|
||||
return execute(args)
|
||||
|
||||
def open_preference(name, **kwargs):
|
||||
open_url('/System/Library/PreferencePanes/%s.prefPane' % name, bundle='com.apple.systempreferences', **kwargs)
|
||||
|
||||
# 获取设备信息
|
||||
def ge_device_info():
|
||||
if Config.cg_session_info is None:
|
||||
Config.cg_session_info = getattr(Quartz, 'CGSessionCopyCurrentDictionary')
|
||||
return Config.cg_session_info()
|
||||
|
||||
def sudo(command: str, timeout=None):
|
||||
stat, out, err = execute('/usr/bin/sudo -S %s' % (command), Config.password, timeout, shell=True)
|
||||
return stat, out, err
|
||||
|
||||
def lock_screen():
|
||||
code = '''tell application id "com.apple.ScreenSaver.Engine" to launch'''
|
||||
return AppleScript.exec(code)
|
||||
|
||||
def unlock():
|
||||
unlock_screen()
|
||||
time.sleep(0.5)
|
||||
keystroke()
|
||||
time.sleep(0.5)
|
||||
success()
|
||||
|
||||
# 唤醒屏幕进入锁屏界面
|
||||
def unlock_screen():
|
||||
code = '''tell application "System Events" to keystroke "a" using command down'''
|
||||
return AppleScript.exec(code)
|
||||
|
||||
# 输入密码
|
||||
def keystroke():
|
||||
code = '''tell application "System Events" to keystroke "%s" using {}''' % (Config.password)
|
||||
return AppleScript.exec(code)
|
||||
|
||||
# 输完密码按下回车
|
||||
def success():
|
||||
code = '''tell application "System Events" to keystroke return using {}'''
|
||||
return AppleScript.exec(code)
|
||||
Reference in New Issue
Block a user