Open specific iMessages chat in new window?

Is there a way to automatically have Messages open the text chat thread with a specific person in a new window? I am often chatting with my wife and would love a macro that would open our chat thread in a separate window, without having to go to the Messages app and double-clicking on the left-hand bar.

Thanks!

Hey @richtack,

Cmd-F

Use the Insert Text by Pasting action to search for name.

Use the Select or Show a Menu Item action to select File > Open Conversation in Separate Window.

Reposition/Resize the window as needed.

-Chris

OMG, of course!!! Thank you. Hardcoded this to my wife, and made it a hot key. Even threw it in an If statement, in case the window is already open. So helpful, THANKS!

1 Like

Hello @richtack,
could you take a screenshot of your macro item? You gave me an idea with your question.
But for me the selection of the existing contact with the action "Insert Txt by Pasting" does not work.
If I select a contact with a new message I cannot select the menu "Select Show a Menu Item action to select File > Open Conversation in Separate Window". This action is then highlighted in light grey.

So I cheated a bit, and took some Applescript I found to select a chat based on a specific email address.
24%20PM

I wonder if this would work by passing a KM variable to the script for targetBuddyHandle? You certainly could do a list of variables in a popup box.

Note, I put the "open conversation in a separate window" menu command in an IF statement, that is checking to see if there is already a window open with that name. Mostly because when I ran the macro a 2nd time, the macro was crapping out. (Because that window was already open, so it is selecting the separate window that automatically exists and the menu item was greyed out)

FYI, I have the window then resizing and moving after this last action, I just couldn't fit it, and it wasn't relevant to your question.
I hope this helps!

Hey @richtack,

Sure.

AppleScript Global Variables

The basic get and set are as follows:

tell application "Keyboard Maestro Engine"
   setvariable "km_var_name" to asTextValue
end tell

tell application "Keyboard Maestro Engine"
   set myAppleScriptVariable to getvariable "km_var_name"
end tell

See the wiki for more and ask questions if needed.

-Chris

Thank you very much for sharing the AppleScripts @richtack :+1:
I have used this now and my macro now works wonderfully.

Since I have three people with whom I regularly chat longer, I have set up a user prompt query.

ScreenFlow

Of course it would also work with 2 persons @richtack :wink:

ScreenFlow

Are you minimizing the main chat window and then making the separate chat window active again before the macro ends? I started to play with that and got distracted by my actual job!!!
:slight_smile:

The AppleScript opens iMessage and then the separate chat window opens. Then I minimize the iMessage main window. :+1:

Here is my screenshot. I have also added the macro. The values for the chat window are 27 inches for my iMac. If necessary they must adapt these.

Chat.kmmacros (40,7 KB)

Hi @appleianer

I noticed that you're using three If Then Else actions to have the macro do different things depending on what the Name variable is. While this obviously works, I thought you might want to know that there is another action designed exactly for this sort of purpose (i.e. branching actions depending on the contents of a single variable) that is both easier to manage and more efficient, because it doesn't execute every If Then Else action every time the macro is run. It's called Switch/Case, and it can be used to improve your macro like this:

Chat 1.1.kmmacros (40.6 KB)
image

All the same actions that are in your original macro are still here, but in this collapsed form, you can see how the macro branches based on the Name variable's value, all in a single enclosing Switch/Case action. Once you know about this action and what it can do it can be very useful, so I hope you find this example helpful.

Many thanks for the improvement and the screenshot @gglick :+1:
I am very grateful for any improvement.
Thank you for improving my macro (1.1) :+1:

1 Like

Okay, I loved your idea, but i'm very lazy, and I hate the idea of having to toggle to a different name if I don't have to. So I created a popup prompt like you did, but I used a variable as the default value. In an applescript before this, I set the value of that variable based on time. So if's before 10:30am, Bryan is the default name, but after 10:30am, Gen is the default.

I also passed the variable into the applescript, and set the actual email address there. This way I don't have to have multiple branches to run. if I want to add, I can just add to the popup and to the applescript.

The applescript to set the variable and pass to the prompt in KM is:
set ToD to (time of (current date))

if ToD < 36000 then
	set msgdefaultAS to "Bryan"
else
	set msgdefaultAS to "Gen"
end if

tell application "Keyboard Maestro Engine"
	setvariable "msgdefault" to msgdefaultAS
end tell

And on the other side, my main applescript is:
tell application "Keyboard Maestro Engine"
set textaddress to getvariable "toText"
end tell

if textaddress is "Bryan" then set targetBuddyHandle to "xxx@gmail.com"
if textaddress is "Gen" then set targetBuddyHandle to "yyy@yahoo.com"

tell application "Messages"
	set thisBuddy to first buddy whose handle is targetBuddyHandle and service type of service of it is iMessage
	set thisChat to make new text chat with properties {participants:{thisBuddy}}
	
end tell

So the whole macro is looking like this:



A very interesting workflow. I will definitely try it out.
Thank you for sharing the Screenshot :+1:

I'm fairly new to all this, so i'm cobbling together what I find from others. There is likely a more streamlined way to do, which i'm very interested in learning!

1 Like

I feel the same way @richtack I am only since 2013 in the Apple world and use KM only since one year somewhat more intensively.
I am every day here in the forum to discover new again. One gets also always very fast help.