主动聊天收到消息Applescript Handler获得两次运行,有人知道为什么吗?

时间:2015-03-10 20:10:42

标签: applescript

任何人都可以帮我解决以下问题:

Applescript for Messages应用程序中的活动聊天消息处理程序运行两次,看起来它收到消息两次,有没有其他人看过这个问题? 下面是我的代码:

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

1 个答案:

答案 0 :(得分:0)

看起来两个处理程序on message received theMessage from theBuddy for theChat on active chat message received theMessage from theBuddy都会被调用。使用(**)对第二个处理程序进行评论,然后重试。如果它按预期工作,请保留更改; - )

玩得开心,迈克尔/汉堡