需要 ios+mac, 把代码里的 18988888888 替换为自己的手机号,
具体可参考 http://blog.csdn.net/u013679882/article/details/61195399,我就是根据这个帖子操作的
现在有个问题,就是无法获取 是否已经锁屏的状态,目前发送 s 获取的状态似乎不正确,感觉不太踏实,希望牛人可以贴出代码
using terms from application "Messages"
on message received theMessage from theBuddy for theChat
--set serviceBuddy to name of service of theBuddy 求出来的是收件人信息
set serviceBuddy to handle of theBuddy -- 发件人手机号 +86 189***
-- 检查发送者是否是我自己
if serviceBuddy = "+8618988888888" then
--display notification "收到指令:" & theMessage & ",发送者:自己" & serviceBuddy
if theMessage is in {"l", "lock"} then
send "Got:" & theMessage to theChat
tell application "Terminal"
do shell script "pmset displaysleepnow"
-- do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend"
end tell
else if theMessage is in {"ln", "locknow"} then
send "Got:" & theMessage to theChat
tell application "Terminal"
do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend"
end tell
else if theMessage is in {"sl", "sleep"} then
send "Got:" & theMessage to theChat
tell application "Finder"
sleep
end tell
else if theMessage is in {"sd", "shut down"} then
send "Got:" & theMessage to theChat
--tell application "Finder"
-- shut down
--end tell
else if theMessage is in {"r", "restart"} then
send "Got:" & theMessage to theChat
--tell application "Finder"
-- restart
--end tell
--else if theMessage = "log out" then
--send " [已忽略-高危] 收到指令:" & theMessage to theChat
--tell application "System Events"
-- log out
--end tell
else if theMessage is in {"s", "status"} then
set runningStatus to "000"
tell application "System Events"
if (running of screen saver preferences) is true then
set runningStatus to "zhen"
else if (running of screen saver preferences) is false then
set runningStatus to "jia"
else
set runninnstatues to "fuck"
end if
end tell
send "status ok[can not got status]" & runningStatus to theChat
else if theMessage is in {"h", "help"} then
send "Welcome!!
l、lock: 锁屏(音乐会继续)
ln、locknow: 锁屏(音乐停止)
sl、sleep:睡眠
sd、shut down:关机[不可用]
r、restart: 重启[不可用]
h、help:帮助
s、status:系统状态
" to theChat
else if theMessage = "1" then
send "test ok" to theChat
end if
end if
end message received
end using terms from
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.