Skip to content

Instantly share code, notes, and snippets.

@rppig42
Created April 10, 2019 01:35
Show Gist options
  • Save rppig42/eb20337790cf17bb0d2c664d52351d5d to your computer and use it in GitHub Desktop.
Save rppig42/eb20337790cf17bb0d2c664d52351d5d to your computer and use it in GitHub Desktop.
休眠时注销Mac微信,以避免其手机消息禁音
script = [[
tell application "WeChat" to activate
tell application "System Events"
tell process "WeChat"
key code 43 using {command down}
end tell
end tell
tell application "System Events"
tell process "WeChat"
tell window "General"
click button "Log Out" of window "General" of application process "WeChat" of application "System Events"
end tell
end tell
end tell
delay 1
tell application "System Events"
tell process "WeChat"
tell window "General"
click button "Log Out" of sheet 1 of window "General" of application process "WeChat" of application "System Events"
end tell
end tell
end tell
]]
function logoutWechat(eventType)
if (eventType == hs.caffeinate.watcher.screensDidSleep) then
print("screensDidSleep")
hs.applescript(script)
elseif (eventType == hs.caffeinate.watcher.screensDidLock) then
--锁屏时似乎无法进行屏幕操作
--print("screensDidLock")
--hs.applescript(script)
end
end
caffeinateWatcher = hs.caffeinate.watcher.new(logoutWechat)
caffeinateWatcher:start()
@yangg
Copy link

yangg commented Apr 10, 2019

直接退出微信就退出登录了,我这里有效

if (eventType == hs.caffeinate.watcher.screensDidSleep) then
    hs.osascript.applescript('tell application "WeChat" to quit')
  end

@rppig42
Copy link
Author

rppig42 commented Apr 10, 2019

我这边直接quit不能生效的原因知道了, 因为我装了防撤回插件...

@chinwayland
Copy link

So all this does is quit WeChat?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment