Active Chat Received Message Applescript Handler gets runs twice, anybody know why?

白昼怎懂夜的黑 提交于 2019-12-08 04:09:24

问题


Please can anyone help me with the below issue:

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

回答1:


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



来源:https://stackoverflow.com/questions/28973195/active-chat-received-message-applescript-handler-gets-runs-twice-anybody-know-w

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!