之前闲来无聊,听朋友说过这个东西,然后稍微看了一些,觉得还是蛮有意思的,今天写出来给大家分享一下。 首先,不知道大家有没有发现,在mac的信息里 重要的前提 也就是说,在”信息”里有脚本处理程序,里面已经有了一些系统预制的一些脚本,当然,都是AppleScript编写的,但是看起来貌似都能看懂,现在要做的就是自己写脚本,然后在这里设置,比如上图里的脚本wjp.applescript就是我自己的。
1,新建一个文本文件,名称随意,后缀为applescript。 2,将下边的代码复制到上边新建的文本文件中,将代码中你的账号替换成你的账号即可,然后保存。代码逻辑很简单,判断+执行。
using terms from application "Messages" on message received theMessage from theBuddy for theChat set serviceBuddy to name of service of theBuddy -- 检查发送者是否是我自己 if serviceBuddy = "你的账号" then if theMessage = "锁屏" then send "已接收" to theChat tell application "Terminal" do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend" end tell else if theMessage = "睡眠" then send "已接收" to theChat tell application "Finder" sleep end tell else if theMessage = "关机" then send "已接收" to theChat tell application "Finder" shut down end tell else if theMessage = "重启" then send "已接收" to theChat tell application "Finder" restart end tell else if theMessage = "注销" then send "已接收" to theChat tell application "System Events" log out end tell end if else display dialog "不是自己账号" & serviceBuddy end if end message received end using terms from3.点击下图标注位置,打开存放脚本的文件夹,然后把刚刚的脚本放进去,然后再回来这个页面选中刚刚添加进去的脚本,就大功告成了
