图文并茂教你用iphone发短信控制自己的mac锁屏、关机等操作

    xiaoxiao2021-03-25  152

    前言

    之前闲来无聊,听朋友说过这个东西,然后稍微看了一些,觉得还是蛮有意思的,今天写出来给大家分享一下。 首先,不知道大家有没有发现,在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 from

    3.点击下图标注位置,打开存放脚本的文件夹,然后把刚刚的脚本放进去,然后再回来这个页面选中刚刚添加进去的脚本,就大功告成了

    注意

    “信息”要处于打开状态,可以设置开机自启动”信息”;代码中对应的汉字命令,大家可以随意改成自己喜欢的字符串;功能还可以扩展很多很多,因为可以调用终端执行shell script,大家自己去探索喽;本人写applescript的经验也不多,就业余爱好,如有错误,非常非常的欢迎指正,感谢;
    转载请注明原文地址: https://ju.6miu.com/read-19481.html

    最新回复(0)