需要 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
1
xwhxbg 2017-12-29 09:54:30 +08:00
呃为啥不做成一个 APP 点按钮控制呢,短信收费还麻烦
|
2
find456789 OP @xwhxbg imessage 不收费的
|
3
lrannn 2017-12-29 10:53:10 +08:00
如果别人给你发 iMessage 的话,好像会有问题啊。。提示 AppleScript 已经运行很长时间了,LZ 测试过吗
|
4
find456789 OP @lrannn 我贴出的那段代码,我用了一周了, 没有出现 bug,其他号码的信息不会有动作的
|
5
lrannn 2017-12-29 13:01:53 +08:00
@find456789 好吧。我给加了段代码,控制 QQ 音乐的一些操作,然后配合 iOS 里的 workflow,挺方便的,就是有的时候电脑 iMessage 接受的慢
|
6
123s 2017-12-29 13:13:39 +08:00
看看
|
7
yuxuan 2017-12-29 13:59:34 +08:00
mark 一下
|