Skip navigation

Creating an AppleScript to Prompt Non-Responsive Chat Buddies in Messages.app

653 Views 1 Reply Latest reply: Jan 28, 2013 9:55 PM by Camelot RSS
jgelements Level 3 Level 3 (520 points)
Currently Being Moderated
Jan 28, 2013 5:41 PM

I am trying to create an AppleScript to prompt non-responsive employees to respond to my chats and get their attention.

 

I am looking for three scenarios:

  1. After 5 unreplied messages, when Messages is not in the foreground, prompt with an alert stating that I need his or her attention
  2. After 5 unreplied messages, when Messages is in the foreground but the buddy's chat is not open, prompt with an alert stating that I need his or her attention
  3. After 5 unreplied messages, when Messages is in the foreground and the buddy's chat is open, prompt with an alert stating that I need them to acknowledge my message

 

I cannot figure out how to limit this script to occurrences when I do not receive a response to 5 messages in a row to my employees. I also cannot get the alerts to occur as specified for when the buddy's chat is already open. In the other two instances, it works.

 

Here is what I have so far:

 

using terms from application "Messages"

 

          on message received from theBuddy for theChat

 

                    if theChat is not first window then

 

                              tell application "Messages"

 

                                        display dialog "Alert! I need your attention momentarily. ~James" buttons {"OK"}

 

                              end tell

 

                    else

 

                              tell application "Messages"

 

                                        display dialog "I need you to acknowledge my message by replying. ~James" buttons {"OK"}

 

                              end tell

 

                    end if

 

          end message received

 

end using terms from

 


Any ideas on what I can do to limit the scenario to 5 unanswered messages? Or what would I do for when the buddy chat is already open?

  • Camelot Level 8 Level 8 (45,670 points)

    Sure, you need either a property or a global variable to keep as a counter. Increment it for each incoming message and post your alert when it reaches the appropriate value.

     

    This (untested) script shoudl give you an idea:

     

    property numMessages : 0

     

    using terms from application "Messages"

              on message received from theBuddy for theChat

     

                        set numMessages to numMessages + 1

                        if numMessages ≥ 5 then

                                  set numMessages to 0 -- reset the counter

     

                                  if theChat is not first window then

                                            tell application "Messages"

                                                      display dialog "Alert! I need your attention momentarily. ~James" buttons {"OK"}

                                            end tell

                                  else

                                            tell application "Messages"

                                                      display dialog "I need you to acknowledge my message by replying. ~James" buttons {"OK"}

                                            end tell

                                  end if

                        end if

     

              end message received

    end using terms from

     

    The premise is that you increment the counter when the message comes in (although you probably want to check it's a message from you rather than some other random user). Once you hit the limit then you reset the counter and do the additional processing to notify the user.

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.