Active Chat Received Message Applescript Handler 运行两次,有人知道为什么吗? [英] Active Chat Received Message Applescript Handler gets runs twice, anybody know why?

查看:16
本文介绍了Active Chat Received Message Applescript Handler 运行两次,有人知道为什么吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请谁能帮我解决以下问题:

Please can anyone help me with the below issue:

Applescript for Messages 应用程序中的 Active Chat Message Handler 运行两次,看起来它收到了两次消息,有没有其他人看到过这个问题?下面是我的代码:

Active Chat Message Handler in Applescript for Messages app runs twice, looks like it receives the message twice, has anyone else seen this issue? below is my code:

global myBuddysName
global textmsg

on readFile(unixPath)
 set foo to (open for access (POSIX file unixPath))
 set txt to paragraphs of (read foo for (get eof foo))
 close access foo
 return txt
end readFile

on msgImage(unixPath)
 tell application "Finder"
  set randomFile to (some file of folder unixPath)
  set the clipboard to (randomFile as «class furl»)
  end tell
  tell application "System Events"
  keystroke "v" using command down
  key code 36
 end tell
end msgImage


using terms from application "Messages"
  on message received theMessage from theBuddy for theChat
    set myBuddysName to 1st item of readFile("Users/username/Desktop/AutomatedTextReply/BuddyName.txt")
    set textmsg to some item of readFile("Users/username/Desktop/AutomatedTextReply/Texts.txt")
    if name of theBuddy is myBuddysName then
        if theMessage contains "text" then
             send textmsg to theBuddy
        end if
        if theMessage contains "image" or theMessage contains "img" then
             msgImage("Macintosh HD:Users:username:Desktop:AutomatedTextReply:Images")
             delay (5)
        end if
        if theMessage contains "video" then
             msgImage("Macintosh HD:Users:usernameDesktop:AutomatedTextReply:Videos")
        end if
   end if
end message received

  on message sent theMessage with eventDescription
  end message sent

  on chat room message received with eventDescription
  end chat room message received

  on active chat message received theMessage from theBuddy
   set myBuddysName to 1st item of readFile("Users/username/Desktop/AutomatedTextReply/BuddyName.txt")
   set textmsg to some item of readFile("Users/username/Desktop/AutomatedTextReply/Texts.txt")
   if name of theBuddy is myBuddysName then
        if theMessage contains "text" then
             send textmsg to theBuddy
        end if
        if theMessage contains "image" or theMessage contains "img" then
             msgImage("Macintosh HD:Users:username:Desktop:AutomatedTextReply:Images")
        delay (5)
        end if
        if theMessage contains "video" then
             msgImage("Macintosh HD:Users:username:Desktop:AutomatedTextReply:Videos")
        end if
    end if
  end active chat message received

  on addressed message received theMessage from theBuddy for theChat with eventDescription
  end addressed message received

  on received text invitation with eventDescription
  end received text invitation

  on received audio invitation theText from theBuddy for theChat with eventDescription
  end received audio invitation

  on received video invitation theText from theBuddy for theChat with eventDescription
  end received video invitation

  on received local screen sharing invitation from theBuddy for theChat with eventDescription
  end received local screen sharing invitation

  on buddy authorization requested with eventDescription
  end buddy authorization requested

  on addressed chat room message received with eventDescription
  end addressed chat room message received

  on received remote screen sharing invitation with eventDescription
  end received remote screen sharing invitation

  on login finished with eventDescription
  end login finished

  on logout finished with eventDescription
  end logout finished

  on buddy became available with eventDescription
  end buddy became available

  on buddy became unavailable with eventDescription
  end buddy became unavailable

  on received file transfer invitation theFileTransfer with eventDescription
  end received file transfer invitation

  on av chat started with eventDescription
  end av chat started

  on av chat ended with eventDescription
  end av chat ended

  on completed file transfer with eventDescription
  end completed file transfer

end using terms from

推荐答案

看起来两个处理程序 on message 都收到了来自 the Buddy for theChat 的消息 on active聊天消息收到来自好友的消息 被调用.使用 (**) 注释第二个处理程序,然后重试.如果它按预期工作,请保留更改;-)

Looks like the both handlers on message received theMessage from theBuddy for theChat and on active chat message received theMessage from theBuddy are called. Comment the second handler using (* and *) and try again. If it works as wanted keep the changes ;-)

玩得开心,迈克尔/汉堡

Have fun, Michael / Hamburg

这篇关于Active Chat Received Message Applescript Handler 运行两次,有人知道为什么吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆