Datatalk / Touch Portal.
Why doesn't Windows have a, per application, setting to allow that specific application to be brought to the front by other apps and itself? It would save a lot of headaches.
Touch Portal
If you're using Touch Portal, WallX, or in general want to force a window to the front, there simply is no clear 'one size fits all' solution... You have to experiment.
In Touch Portal, you have several options:
1. Launch the program directly
2. Launch the program, then give it focus
3. Start a batch file
4. Start multiple programs from a batch file
5. A combination of the above
Option 4 never worked reliably for me, so I use either Touch Portal's build-in 'Focus' command, or used batch files.
Update: this is caused by Windows only allowing a focus change ONCE. When an app gives another app focus, it can't change it again. (See also 'Two Stages' at the bottom of this post.)
Start and Activate Window
This seems to actually activate and bring the window forward. Some apps work perfectly fine using this approach, for example opening an Excel spreadsheet:
- Run & Open / Open File will let you open any file with the associated application
- Run & Open / Start Application will launch the specified application
- Utility / Focus Application will bring the first window with the given title to the front and give it focus
Unfortunately, that doesn't always work 😒 so I had to resort using a batch file (more on later).
Notes:
1. Open File and Start Application will not wait until the application has been launched. Windows may return control to Touch Portal before the app is done, or the app may be slow to update its title bar. One way around this is to add a Delay in between opening the file and activating the window.
2. You can find a list of open Windows using cmdow /T from the command line.
3. Although it seems the titlebar contains a name, sometimes the application window can't be activated using that name. Often simply shortening the name works. For example, trying to activate the window using 'outline.xlsx - excel' didn't work, but using 'outline.xlsx' did.
4. Some apps simply don't cooperate. I have no clue why. Typically, launching them using a batch file did get it to work...
Using Batch Files
Up front, any scripts I tried worked best when using the 'Script & Open' option to start a batch file. I have no clue why.
Inside the called batch file you have different ways to launch a program. Again, there's no perfect way that works for everything. Here are five different approaches. You have to try which one works best on a trial and error basis.
Tools used in the batch files
- waitwindow - wait for a window
- waitfile - wait for a file
- cmdow- manipulate windows
- nircmd - NirSoft's multi tool, can be used to send keystrokes, and many other things
- tar - included with Windows 10 /11
- start - included with Windows
- timeout - included with Windows
- immprep - HTML processor to strip the exported HTML file
Launch an application from a batch file
1. Direct
You can simply provide a direct path plus an executable name, like:
- c:\software\totalcmd\totalcmd64.exe
... but it doesn't always pop up in front, so I need to make another call to cmdow.
2. Change the path first
Sometimes you have to start the executable from within a specific folder, so
- c:
- cd c:\software\totalcmd
- totalcmd64.exe
- start c:\software\totalcmd\totalcmd64.exe
- start c:\software\totalcmd\totalcmd64.exe %1 %2
- start C:\software\wincmd\TOTALCMD64.EXE %1 %2
- waitwindow "total*" forever
- cmdow "total*" /vis /ena /res/ /act
- exit
- c:\> start /?
- start "Chrome" /B "C:\Program Files\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 1" %1
4. Use waitwindow and cmdow
Touchportal behaves differently. It would start most of the time, but the most reliable way was this approach (which doesn't make any sense, alas):
- waitwindow "notgonnawait" nowait startifnotopen "C:\Program Files (x86)\Touch Portal\TouchPortal.exe"
- waitwindow "touch portal*" forever wait
- cmdow "touch portal*" /ena /vis /act
- exit
I wasn't able to reliably open the excel file in the example above, so I had to resort to launching a script (batch file) from Touch Portal:
In the associated batch file:
- start c:\googledrive\mynovel\outline.xlsx
- waitwindow "outline.xlsx*" 4
- cmdow "outline.xlsx*" /vis /ena /act
- exit
The combo above works reliably.
Again, any scripts I tried worked best when using the 'Script & Open' option to start a batch file.
Examples
1. Launching Chrome with a specific profile
- start "Chrome" /B "C:\Program Files\Google\Chrome\Application\chrome.exe" --profile-directory="Default" "%1"
2. TotalRecorder
- waitwindow "*- total recorder" nowait start "C:\Program Files (x86)\HighCriteria\TotalRecorder\TotalRecorder.exe"
- waitwindow "*- total recorder"
- cmdow "*total recorder" /vis /ena /res /act
- exit
3. TotalCommander
- start C:\software\wincmd\TOTALCMD64.EXE %1 %2
- waitwindow "total*" forever wait
- cmdow "total*" /vis /ena /res/ /act
- exit
Two stages: Immersive Reader launched from within Google Docs
Once you've activated another window, you can't change the focus to another window. This is a deliberate limitation in Windows 8 / 10 / 11.
So, what I wanted to accomplish was: start MS Edge Immersive reader from within GoogleDocs. I used a multi stage stage approach for that.
1. You need an application that runs in the background and doesn't steal focus. TouchPortal does that.
2. I use a line '<< immersive >>' anywhere in my GoogleDocs document to tell immprep where the text to read starts.
4. Whilst working in GoogleDocs I hit a TouchPortal button, and it sends the keypresses to GoogleDocs to export the current document as a HTML file.
4. Next Touch Portal launches a batch file.
5. The batchfile then uses immprep (a little DIY tool) to process the archive exported by Google Docs (it strips everything up to a specific point, and converts '--' to 'emdash').
6. When the file has been processed the batch file launches Edge with the processed HTML file. At this point Edge will get the focus.
7. I then send from the batch file the 'start reading' command to Edge, using nircmd.
- immprep downloads auto cleanup mdash unread
- if errorlevel 1 goto noedge
- nircmd sendkeypress ctrl+shift+u
- :noedge
- exit
Update: the new version of Immprep uses different command line options. See here.
In the second half of this video you see how that works in practice.
Drop me a line in the comments section if you want a copy of ImmPrep.
No comments:
Post a Comment