Is there an command i can use on cmd to switch to/focus on selected app window?
Lets say i have three apps working: A, B, C and currently i m focused on B. Is there a command (not shortcut) to switch to/focus on app A?
Maybe can i do it with batch?
Im working on windows.
To change your command prompt to focus on a different drive, just type the drive letter followed by a colon. From there you can use the “cd” command to access other directories on that different drive.
%%a are special variables created by the for command to represent the current loop item or a token of a current line. for is probably about the most complicated and powerful part of batch files. If you need loop, then in most cases for has you covered.
Use a switch once by adding it to the Run command In the Run dialog box, type a quotation mark, enter the full path for the app's .exe file, and then type another quotation mark. Alternatively, click Browse to locate and select the file. In this case, the quotation marks are supplied automatically.
The P (process) command submits the command constructed in the primary output buffer to the TCL command processor.
This should work:
echo (new ActiveXObject("WScript.Shell")).AppActivate("app A"); > focus.js
cscript //nologo focus.js
del focus.js
try with sendKeys.bat :
call sendkeys.bat "Title A" ""
The first argument is the beginning of the title you want to switch to (if it is Some Title
you can use only Some
if it is unique enough). Second argument are empty double quotes.
In general the script is used to send keys to a particular window. But if you left the second parameter empty (like ""
) it will not send any keys.
My solution in this gist is very much based on @npocmaka's answer, but it gives a more complete and exact answer to the OPs specific question (I had to incorporate a couple more references to get to this): it activates and restores the named app if it is already running, or starts it if not.
I'll repeat the code here for completeness - replace the image name of the app and the path required to start it as you need:
@if (@X)==(@Y) @end /* JScript comment
@echo off
setlocal
for /f "tokens=2" %%i in ('tasklist /FI "IMAGENAME eq Fork.exe" ^| find /I "Fork.exe"') do set pid=%%i
if "%pid%" == "" (
%localappdata%\Fork\Fork.exe
) else (
cscript //E:JScript //nologo "%~f0" "%~nx0" "%pid%"
)
exit /b %errorlevel%
endlocal
@if (@X)==(@Y) @end JScript comment */
var sh=new ActiveXObject("WScript.Shell");
if (sh.AppActivate(WScript.Arguments.Item(1)) == 0) {
sh.SendKeys("% r");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With