Goal
I want to have a AppleScript that let's me get the ID or something similar of the selected Messages.app conversation/chat, and then later have a AppleScript which can open the correct Messages conversation/chat corresponding to this ID.
- Get ID/reference to currently selected Messages.app chat
- Open a particular Messages.app chat based on a ID/reference
What I have tried so far
With Mail.app I can do the following:
tell application "Mail"
set selectedMessages to selection
set theMessage to item 1 of selectedMessages
set messageid to message id of theMessage
-- Make URL (must use URL-encoded values for "<" and ">")
set urlText to "message://" & "%3c" & messageid & "%3e"
return urlText
end tell
But with Messages.app, there is to selection
object.
Tried to get the content of the clipboard
to see if there is any ID's or something of value which can be used, but it looks like the clipboard access is not as powerful as it is through cocoa programming (where you can get a lot of meta data and alternative clipboard content).
Double click on a conversation so that it opens with it's own window. Tried to get the ID of this window, and then open it later. Didn't work.
To use this AppleScript script, as a script (.scpt) or an application (.app), you need to first select the target conversation in the list of conversations in Messages.app that you want it to always return to thereafter, and initially run this twice. This then sets
property theSelectedRow : 0
toproperty theSelectedRow : i
where the value ofi
will be therow
number of the conversation in the list of conversations that was selected when initially run twice. The script also setsproperty thisName : ""
to a value that is the name contained within thedescription of UI element 1 of row i
. Between the value of these two properties, the script will always set focus back to the selected target conversation in subsequent runs, providing it still exists, even as itsrow
number changes. If the selected target conversation no longer exists, the user is notified.Read the comments throughout the script so as to have an understanding of what the code is doing.
AppleScript code:
Note: This was written and tested under OS X 10.8.5, however, I believe it will work as is under later versions of OS X/macOS and Messages.app, even with the current macOS 10.13 beta.
Additionally, the script employs minimal error handling and is absent of any
try
statements andon error
handlers. Although aside from the value from thedelay
commands, that can be adjusted as/if needed, it should run fine without additional error handling. As always, the user can add/remove and or adjust the code as/if needed or wanted.