Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable globalSummon / quakeMode to work even when there isn't a running Terminal #9996

Open
zadjii-msft opened this issue Apr 29, 2021 · 59 comments
Assignees
Labels
Area-Remoting Communication layer between windows. Often for windowing behavior, quake mode, etc. Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Terminal The new Windows Terminal.
Milestone

Comments

@zadjii-msft
Copy link
Member

zadjii-msft commented Apr 29, 2021

This is probably going to need the "headless monarch" work we theorized. Different parts to this:

  • We've already got startOnUserLogin which starts the Terminal window.
  • Is any window the monarch then?
  • Is the monarch a phoenix (when it's killed, who restarts it?)

I've had many more thoughts on the matter in the past, I just need to have somewhere to put them.

@zadjii-msft zadjii-msft added the ⛺ Reserved For future use label Apr 29, 2021
@zadjii-msft zadjii-msft changed the title <reserved> Enable globalSummon / quakeMode to work even when there isn't a running Terminal May 25, 2021
@zadjii-msft zadjii-msft added Area-Remoting Communication layer between windows. Often for windowing behavior, quake mode, etc. Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Terminal The new Windows Terminal. and removed ⛺ Reserved For future use labels May 25, 2021
@ghost ghost added the Needs-Tag-Fix Doesn't match tag requirements label May 25, 2021
@zadjii-msft zadjii-msft added this to the Terminal Backlog milestone May 25, 2021
@dag03tsc
Copy link

dag03tsc commented Jun 1, 2021

Is the monarch a phoenix (when it's killed, who restarts it?)

I'm pretty sure this already came to your mind before, but what about using the service approach?
It'd only require the tray icon feature to enable the persistence and provide some control over the service itself.

I guess that'd also allow termination commands like exit, while keeping the globalSummon or quakeMode available, for as long as the service is running.

Could it be useful to have some kind of a master orchestrator service? Something like a service to host and manage all WT instances?

@kensykora
Copy link

Been testing out the preview channel and I LOVE quake mode. Since the terminal is so core to my development workflow, it'd be HUGE if this launched on startup so it felt like a core part of the OS.

@hensz
Copy link

hensz commented Jul 20, 2021

Is this issue purely about starting (and keep running) Terminal at startup? I was looking for a way to manually start a terminal in Quake mode, just as asked for in issue #10206.

@zadjii-msft
Copy link
Member Author

I was looking for a way to manually start a terminal in Quake mode

That'd be wt -w _quake. See also the docs

@hensz
Copy link

hensz commented Jul 21, 2021

This doesn't work since I have both the stable and the preview version installed, and wt runs the stable version. Most likely I could simply uninstall the stable version. Is there any other way to launch the preview?

@zadjii-msft
Copy link
Member Author

Is there any other way to launch the preview?

You could always change wt to open the Preview version. To do that, you can check out the "Manage app execution aliases" page in the settings

@hensz
Copy link

hensz commented Jul 21, 2021

Hmm, if I do this and try to run wt, I get an error from the stable version:
[Window Title]
C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.8.1521.0_x64__8wekyb3d8bbwe\wt.exe

[Content]
Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item.

@hensz
Copy link

hensz commented Jul 22, 2021

OK, when I remove the stable version running wt successfully launches the preview, and also launching in Quake mode works fine. Thanks a lot! Now I only need to figure out how I can add this command as a shortcut to my start menu 🙈

@NinovanderMark
Copy link

NinovanderMark commented Aug 11, 2021

If there were an option to start Windows Terminal in Quake mode, but hidden, that would solve it in my book.

Something like this: wt -w _quake --hidden

@lhecker lhecker added this to the Terminal v1.19 milestone Apr 12, 2023
@zadjii-msft
Copy link
Member Author

Since folks in this thread are probably interested: https://github.com/microsoft/terminal/releases/tag/v1.18.1421.0 added the global setting compatibility.allowHeadless, which should let the Terminal keep running in the background after closing all windows. This'll let the global hotkeys keep working, even if the Terminal isn't open.

    // Add support for running the Terminal without _any_ windows #14944
    // (you probably also want at least `quakeMode` or a `globalSummon`)
    "compatibility.allowHeadless": true,

There's still more work to do, and I'm tracking it as follows:

@vadimkantorov

This comment was marked as off-topic.

@zadjii-msft

This comment was marked as off-topic.

@vadimkantorov

This comment was marked as off-topic.

@DrLeh
Copy link

DrLeh commented Jun 16, 2023

I use the following hotkey in Autohotkey to help enable this:

$#`::
If (ProcessExist("WindowsTerminal.exe"))
    Send #``
else
    Run "wt"
::

I couldn't get this to actually start in quake mode, so in reality what i have to do is press `#``, this opens terminal, then press it again to get quake mode, then again to hide it, then close the original terminal.

This is far from optimal but at least gives me a single hotkey to get terminal open and into quake mode without having to open wt through some other means.

@NewtonChutney
Copy link

Since folks in this thread are probably interested: https://github.com/microsoft/terminal/releases/tag/v1.18.1421.0 added the global setting compatibility.allowHeadless, which should let the Terminal keep running in the background after closing all windows. This'll let the global hotkeys keep working, even if the Terminal isn't open.

    // Add support for running the Terminal without _any_ windows #14944
    // (you probably also want at least `quakeMode` or a `globalSummon`)
    "compatibility.allowHeadless": true,

Meanwhile, can the preview release of WT point to a schema with these keys in it?
I did try changing the schema, and didn't find this key though.. This seems missing.. 🫠
But the key value pair is detected! 😌

20230703_124156.jpg

@Memoraike
Copy link

Memoraike commented Jul 31, 2023

I use the following hotkey in Autohotkey to help enable this:

$#`::
If (ProcessExist("WindowsTerminal.exe"))
    Send #``
else
    Run "wt"
::

I couldn't get this to actually start in quake mode, so in reality what i have to do is press `#``, this opens terminal, then press it again to get quake mode, then again to hide it, then close the original terminal.

This is far from optimal but at least gives me a single hotkey to get terminal open and into quake mode without having to open wt through some other means.

Try this:

ProcessExist(Name){
	Process,Exist,%Name%
	return Errorlevel
}

#If !ProcessExist("WindowsTerminal.exe")
#`::
Run wt -w _quake
Return

image

@H4M5TER
Copy link

H4M5TER commented Aug 10, 2023

dirty way to start it minimized: wt -w _quake powershell -nologo -window minimized

Since it would open a new shell nested in default shell, I put pwsh -nologo -window minimized on a standalone wt profile and use wt -w _quake -p quake to launch.

@MolotovCherry
Copy link

MolotovCherry commented Oct 28, 2023

As of my current posting date, after reading all the above, this works for me

As a startup task. (By default it won't run the initial user profile; if you don't care about this, feel free to remove the command and even NoExit)
wt -w _quake pwsh -nologo -window minimized -NoExit -Command "& { . 'C:\Users\><User>\Documents\PowerShell\Microsoft.PowerShell_profile.ps1' }"

Inside your settings.json (so you can still open quake after terminal/quake windows are closed)
"compatibility.allowHeadless": true,

Now it always shows up no matter what (seems that a side effect as of the latest version of this posting date, is actual terminal windows open behind all others)

@unennhexium
Copy link

unennhexium commented Nov 3, 2023

@MolotovCherry

I followed your instructions and got this error:

[error 2147942402 (0x80070002) when launching `"powershell -nologo -window minimized"']

⚠️Error

I also read all above.


Please clarify the exact command for the "target" field of startup shortcut.
If I understand correctly, you are creating a shortcut in this directory:

%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup

📝Properties

@MolotovCherry
Copy link

MolotovCherry commented Nov 3, 2023

@unennhexium I have mine in a task schedule job. (trigger at log in, action start a program)
Program C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\wt.exe
Args -w _quake powershell -nologo -window minimized -NoExit -Command "& { . 'C:\Users\<user>\Documents\PowerShell\Microsoft.PowerShell_profile.ps1' }"
Start in C:\Users\<user>

I'm sure a shortcut way exists, but I have no need to experiment with that since it's already working for me.

In either case, I noticed your command is "powershell -nologo -window minimized", why is that double quoted? Double quotes turn it into one argument. It is looking for a program named "powershell -nologo -window minimized", but no such program exists (the program is powershell). That should be simply, powershell -nologo -window minimized

In either case, I don't know exactly what you're doing, so I can't really debug that for you. The usual rules apply. Make sure wt, powershell is in PATH, etc

(Also, while writing this, I noticed I should use pwsh instead of powershell, since the latter is the built in one in windows, where I have the newest powershell installed, which calls it pwsh instead)

@amzon-ex
Copy link

amzon-ex commented Nov 3, 2023

Program C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\wt.exe
Args -w _quake powershell -nologo -window minimized -NoExit -Command "& { . 'C:\Users\<user>\Documents\PowerShell\Microsoft.PowerShell_profile.ps1' }"
Start in C:\Users\<user>

@MolotovCherry could you please tell me what -NoExit does?

@MolotovCherry
Copy link

MolotovCherry commented Nov 3, 2023

Program C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\wt.exe
Args -w _quake powershell -nologo -window minimized -NoExit -Command "& { . 'C:\Users\<user>\Documents\PowerShell\Microsoft.PowerShell_profile.ps1' }"
Start in C:\Users\<user>

@MolotovCherry could you please tell me what -NoExit does?

@amzon-ex According to microsoft docs, it:

Doesn't exit after running startup commands.

So, it just keeps the shell open after running a command.

@unennhexium
Copy link

unennhexium commented Nov 3, 2023

@H4M5TER

Could you describe in detail what you do?

I do the following

  • Сreate a new terminal profile called quake
    📑Profile
  • Сreate a shortcut that launches a terminal with this profile
    📝Shortcut
  • In the end I get an error
    ⚠️Error

🚩This also happens if I simply open a new tab with this profile in an already active terminal window.

@unennhexium
Copy link

unennhexium commented Nov 3, 2023

@MolotovCherry

Ok. I did this using Task Scheduler

  • Add a trigger

    🪝Trigger
    🪝Trigger *
  • Add an action

    🎣Action
    🎣Action *
  • I'm getting the same error

    ⚠️Error

Just in case, I'm replacing powershell with pwsh. Both are in my PATH.
The wt has also been added to PATH. That is, they can all be launched from the command line.

✅Checking access
Administrator_PowerShell_2023-11-04.01-40-47-Trim.mp4

I also did not include any additional quotation or other chars. I checked for extra spaces inside and at the ends of the command and its arguments. None of this was found.

This method still doesn't work for me.


The Task Scheduler allows to export tasks in xml format. I did this for my task and am attaching the code from this file. So you can "debug".

✏️wt_task.xml
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2023-11-03T19:04:05.6192719</Date>
    <Author>LAPTOP-PC\User</Author>
    <Description>Launches Windows Terminal in the background to be activated in Quake mode using (⊞ + `) in the future</Description>
    <URI>\Windows Terminal</URI>
  </RegistrationInfo>
  <Triggers>
    <LogonTrigger>
      <Enabled>true</Enabled>
    </LogonTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-21-3286135726-1618621029-3948465185-1014</UserId>
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Users\User\AppData\Local\MIcrosoft\WindowsApps\wt.exe</Command>
      <Arguments>-w _quake pwsh -nologo -window minimized</Arguments>
      <WorkingDirectory>C:\Users\User</WorkingDirectory>
    </Exec>
  </Actions>
</Task>

@MolotovCherry
Copy link

MolotovCherry commented Nov 6, 2023

@unennhexium Your task works fine for me verbatim (except I changed the user path to mine).

@MadameMinty
Copy link

In Start Menu\Programs\StartUp, I put a shortcut to wt.exe -w _quake with the dropdown Run set to Minimized. Upon startup, WT flickers once, then Quake Mode shortcut key works to show/hide the terminal until I alt+F4 or otherwise shutdown the process. It's not perfect, but close enough.

@fleps
Copy link

fleps commented Mar 7, 2024

I can't believe we still don't have a WT argument --minimized yet.

The solutions proposed here do not work flawlessly, one (big) caveat for me was losing the ability to open your default profile Elevated / as administrator, even if configured on WT.

My workaround to have it as ADMIN was similar to above:

  • Go to your startup folder (run shell:startup)
  • Create a shortcut and on Target add wt pwsh -window minimized (I don't use quake mode, I have my Win+` set to globalSummon, you can add/keep the quake parameters if wanted)
    • In this case, make sure on your WT Settings > Appearance you have the option to hide the terminal to tray area when minimized
  • Set "Run" option also to Minimized (this prevents any flicker)
  • Click on Advanced button and check "Run as Administrator" (don't use the similar option from Compatibility tab, it's not the same, you want the one from the Advanced button)
  • Apply, OK.

Still, can we PLEASE get a --minimized considering we already have --maximized???

@GeorgeGedox
Copy link

GeorgeGedox commented Mar 13, 2024

Could we know what is stopping the devs from implementing a proper option to start windows terminal in the background on startup if we want this?
I'd like to be able to have quake mode available without using weird startup hacks or having a terminal instance active at all times in my taskbar, that defeats the purpose of quake mode.

The whole idea behind quake mode is to have a hotkey that opens the terminal at any time from anywhere without any previous intervention to "prep" it beforehand.

@zadjii-msft
Copy link
Member Author

Could we know what is stopping the devs from implementing a proper option to start windows terminal in the background on startup if we want this?

Time, basically. I haven't had the chance to loop back around on --headless (as mentioned in #9996 (comment)), or the "headless" startup task (as referenced in #9996 (comment) and further spec'd in #13630 (comment)).

Not sure when exactly I'll have a chance to. I don't think these would be terribly difficult if someone in the community wanted to contribute either here. I could definitely provide guidance and pointers if someone runs into any questions.

@MaverickMartyn
Copy link

I can't believe we still don't have a WT argument --minimized yet.

The solutions proposed here do not work flawlessly, one (big) caveat for me was losing the ability to open your default profile Elevated / as administrator, even if configured on WT.

My workaround to have it as ADMIN was similar to above:

  • Go to your startup folder (run shell:startup)

  • Create a shortcut and on Target add wt pwsh -window minimized (I don't use quake mode, I have my Win+` set to globalSummon, you can add/keep the quake parameters if wanted)

    • In this case, make sure on your WT Settings > Appearance you have the option to hide the terminal to tray area when minimized
  • Set "Run" option also to Minimized (this prevents any flicker)

  • Click on Advanced button and check "Run as Administrator" (don't use the similar option from Compatibility tab, it's not the same, you want the one from the Advanced button)

  • Apply, OK.

Still, can we PLEASE get a --minimized considering we already have --maximized???

In regards to running as admin, I use PowerToys' Keyboard Manager to run terminal on CTRL+ALT+T, and CTRL+SHIFT+ALT+T runs it as administrator.
Assuming you can make WT start in quake mode with a parameter, that should work too.

@zadjii-msft zadjii-msft modified the milestones: Terminal v1.19, Backlog May 31, 2024
@only-su
Copy link

only-su commented Jun 19, 2024

I can't believe we still don't have a WT argument --minimized yet.
The solutions proposed here do not work flawlessly, one (big) caveat for me was losing the ability to open your default profile Elevated / as administrator, even if configured on WT.
My workaround to have it as ADMIN was similar to above:

  • Go to your startup folder (run shell:startup)

  • Create a shortcut and on Target add wt pwsh -window minimized (I don't use quake mode, I have my Win+` set to globalSummon, you can add/keep the quake parameters if wanted)

    • In this case, make sure on your WT Settings > Appearance you have the option to hide the terminal to tray area when minimized
  • Set "Run" option also to Minimized (this prevents any flicker)

  • Click on Advanced button and check "Run as Administrator" (don't use the similar option from Compatibility tab, it's not the same, you want the one from the Advanced button)

  • Apply, OK.

Still, can we PLEASE get a --minimized considering we already have --maximized???

In regards to running as admin, I use PowerToys' Keyboard Manager to run terminal on CTRL+ALT+T, and CTRL+SHIFT+ALT+T runs it as administrator. Assuming you can make WT start in quake mode with a parameter, that should work too.

When using powertoys Keyboard Manager to run terminal is there a way to make it not open a new tab when a window already exists? In other way to make the command create a window when none exists or just invoke the existing tab instead of opening a new one whe it does?

@Memoraike
Copy link

When using powertoys Keyboard Manager to run terminal is there a way to make it not open a new tab when a window already exists? In other way to make the command create a window when none exists or just invoke the existing tab instead of opening a new one whe it does?

For your purpose, autohotkey will work. It doesn't work perfectly with minimized terminal windows, but as a temporary solution it's great. Don't forget to change keyboard shortcuts if necessary.

#Requires AutoHotkey v2.0
#SingleInstance

DetectHiddenWindows true
terminalName := "WindowsTerminal.exe"

; [Win Shift Enter] If the terminal is already open, activate it. Otherwise, open it.
#+Enter:: {
   if (pid := ProcessExist(terminalName)) {
       if WinExist("ahk_pid" pid) {
           PostMessage 0x0112, 0xF120, , , WinGetID("ahk_pid" pid)
           WinActivate
       }
   } else {
       Run("wt")
   }
}

; [Win Enter] Open the terminal in a new window.
#Enter:: {
   Run("wt")
}

; [Win `] Open the terminal in a quake mode. Only works if the terminal is not already open. Require setting same hotkey in the terminal.
#HotIf !ProcessExist(terminalName)
#`:: {
   Run("wt -w _quake")
}

To work correctly with minimized windows, you should enable this option in the settings:

image

@MaverickMartyn
Copy link

MaverickMartyn commented Jul 5, 2024

For anyone on Windows 11, you can start a new Terminal using WIN+X, followed by I for Terminal or A for elevated Terminal.
It's not perfect, but it works without any 3rd party software or setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Remoting Communication layer between windows. Often for windowing behavior, quake mode, etc. Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

No branches or pull requests