Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Toggle Start/Minimize/Restore Windows Terminal

Description
Just a quick mod to ZipD's Whatsapp toggle script to do the same with the new Windows Terminal app.
Language
C#.net
Minimum Version
Created By
István Farmosi
Contributors
-
Date Created
Apr 9, 2021
Date Last Modified
Apr 9, 2021

Scripted Function (Macro) Code

/*
 * Heavily based on ZipD's "Toggle Start/Minimize/Restore Whatsapp" script - Thanks mate :)
 * 
 * NOTE TO USERS
 *
 * You will most likely need to change the path at the end of the script. 
 * You can figure out the right value by finding WindowsTerminal.exe in 
 * Task Manager then selecting "Open File Location" in the context menu. Hold
 * shift while right clicking in the Explorer window and select "Copy as path",
 * then you can just paste that right in after the @ sign.
 *
 * OPTIONAL MODIFICATION
 * By default, this script will hide the terminal from the windows taskbar
 * when you hide the terminal. You can change this by simply removing the
 * line that calls "BFS.Window.RemoveFromWindowsTaskbar(hwnd);".
 * 
 */

using System;
using System.Drawing;

public static class DisplayFusionFunction
{
	public static void Run(IntPtr windowHandle)
	{
		bool isRunning = BFS.Application.IsAppRunningByFile("*WindowsTerminal.exe");
		
		//Check if running
		if(isRunning)
        {
            //Get the window handle
            IntPtr hwnd = BFS.Application.GetMainWindowByFile("*WindowsTerminal.exe");

            //Check if already minimized
            bool isMinimized = BFS.Window.IsMinimized(hwnd);
            if(isMinimized)
            {
                //Restore 
                BFS.Window.Restore(hwnd);
            }
            else
            {
                //Minimize 
                BFS.Window.Minimize(hwnd);
                BFS.Window.RemoveFromWindowsTaskbar(hwnd);
            }
        }
        else 
        {
            //Start if not running
            BFS.Application.Start(@"C:\Program Files\WindowsApps\Microsoft.WindowsTerminalPreview_1.7.572.0_x64__8wekyb3d8bbwe\WindowsTerminal.exe");
        }
	}
}