1

Windows 8.1 , ConEmu 170316 [32] {Preview}

I have multiple Conemu instances running, where each instance equals one "workspace".

I would like to be able to switch to this workspaces with autohotkey or pywinauto. However they require a criterion for selecting the right window, and usually I employ a combination of window title and or window class type.

Is there any setting in conemu that can help me achieve this criterion identifiation for window selection? If there isn't, I will have to write the PID down somewhere when I start the conem windows, then read it to bring up the right window at window activation time.

MrR
  • 411
  • 5
  • 12
  • I think this question is more suited for SuperUser since you're asking about program settings, not about programming. – BrenBarn Jul 30 '17 at 18:21
  • 1
    @BrenBarn not necessarily. I'm open to other suggestions that do not necessarily involve settings changed only. If I have to code something in python to get around this limitation (I suggest one of the off-the-top-of-my-head ways of doing it), I am happy to do that. Open to suggestions. – MrR Jul 30 '17 at 18:26
  • How do you run ConEmu instances? I don't understand why do you want to use external hotkey managers to activate ConEmu window... – Maximus Jul 31 '17 at 07:44
  • 1
    There is a FAQ: https://conemu.github.io/en/FAQ-11.html#q-11-1 – Maximus Jul 31 '17 at 20:52
  • OMG it is there! TY @Maximus - I tried googling with "conemu window title" and checked quite a few results - I came to the conclusion that this wasn't possible in Conemu.I also used the documentation quite a lot, I should have gone through the FAQ more thoroughly. – MrR Aug 01 '17 at 15:37
  • RE: "How do you run ConEmu instances? I don't understand why do you want to use external hotkey managers to activate ConEmu window..." For two reasons. (1) I want to manage all my shortcuts programmatically, not through GUI setups. And I already have quite a stake in ahk / pywinauto, so it fits into my current setup rather seamlessly. (2) [the native "windows shortcuts" hotkeys method in your docs](https://conemu.github.io/en/FAQ-11.html#q-11-1) would create a new conemu instance every time the shortcut is invoked - not activate an existing window. Or am I misunderstanding something? – MrR Aug 01 '17 at 16:00
  • 1
    @Maximus thank you for the AMAZING Conemu. – MrR Aug 01 '17 at 16:02

2 Answers2

1

I can say only about pywinauto. When you call app = Application().start('ConEmu64.exe') pywinauto already remembers process PID and every new WindowSpecification object assumes this PID. Of course, it's true only if you're controlling start of ConEmu (or any other app). More details can be found in the Getting Started Guide.

Method app.connect(title="some unique tab name") will also remember the PID in app object. But if there are few instances with the same title, you need to disambiguate it using found_index=0 criterion, for example. Or right click on the tab and choose "Rename tab..." context menu item which changes the window title.

I took a short look at ConEmu. Toolbars and tabs are visible even to Spy++. So the most of actions can be automated. Just not sure about console inside a tab. If you want to type some commands, it's much better to use standard Python module subprocess because GUI automation for console programs looks very very strange. ;)

Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
  • Thanks for your insightful response. "it's true only if you're controlling start of ConEmu (or any other app)" -> Yes, and I don't necessarily have to keep it in memory,I can keep in a good known place for the activating program (which might be different). "Or right click on the tab and choose "Rename tab..." context menu item which changes the window title." -> Tabs are named programmatically. I don't want to have to click on anything. At any point in time any tab might have been selected, so I need to check the window table for a match against all the tabs that I know for that session. – MrR Jul 30 '17 at 21:12
  • "I took a short look at ConEmu. Toolbars and tabs are visible even to Spy++. So the most of actions can be automated. Just not sure about console inside a tab. If you want to type some commands, it's much better to use standard Python module subprocess because GUI automation for console programs looks very very strange. ;)" Thank you, this is interesting to know. I just had a requirement of activating the right window now (my "workspace"), then I can navigate the tabs using conemu native mechanisms. – MrR Jul 30 '17 at 21:15
  • You can also build conemu command lines / command files from python dynamically (for instance I build a set of git consoles for each git repo in a folder I specify). Pretty easy and powerful. – MrR Jul 30 '17 at 21:16
1

As per faq (ty Maximus) - see option 1:

1) Use -title “Window name” switch to explicitly set window title of new ConEmu instance. The example below starts new ConEmu window with title My server and ssh to your.server.com inside. Does not matter if you run another tab, or several tabs from task, the ConEmu window title remains My server. So you may rely on the title for selecting the window with class name VirtualConsoleClass.

Option 2 is also valid. I'd have to (1) create a config, and (2) hardcode the hashed id in ahk / pywinauto. Just using the window title name seems the right thing to do in my case, the app id setup seems overkill

2) Windows 7 introduced AppUserModelID. ConEmu uses executable path name and some switches (like -config, -loadcfgfile, -quake) to create a hash to form AppID, which you may see in the About / SysInfo. Current version shows 1d5372066082f23b41ba6aa278e56e9d::163. The trailing ::163 depicts ConEmu internal protocol version which may (and most probably would) be changed in the future. The hash itself is expected to be unchanged. You may query the ID from running ConEmu process using Windows API function GetApplicationUserModelId.

Thank you Maximus!

MrR
  • 411
  • 5
  • 12