分享发短信控制 mac 的关机锁屏重启 的代码,顺便求大家改进下,目前无法获取锁屏状态

2017-12-29 09:37:46 +08:00
 find456789

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

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/418488

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX