Skip to content

Instantly share code, notes, and snippets.

@jondolan
Created March 6, 2017 03:30
Show Gist options
  • Save jondolan/9eb0a9eefffac3ae67445763973e9f58 to your computer and use it in GitHub Desktop.
Save jondolan/9eb0a9eefffac3ae67445763973e9f58 to your computer and use it in GitHub Desktop.
AutoHotkey Windows drop down terminal
;; Jon Dolan ;;
;; V1.0 - March 5th, 2017 ;;
;; Windows emulator for Yakuake/Guake written in AHK (https://autohotkey.com) ;;
;; Provies drop down capabilities to whatever Windows terminal program you please ;;
;; By default, this script uses Bitvise xterm with the hotkey F12 ;;
;; But it is configurable by changing the global variables below ;;
;; To compile this script after changing it to your liking: ;;
;; https://autohotkey.com/docs/Scripts.htm#ahk2exe ;;
;; Best to just download/install autohotkey and right click on the .ahk file and select "compile" ;) ;;
;;;;;;;;; GLOBAL AHK SETTINGS (DO NOT MODIFY) ;;;;;;;;;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;;;;;;;;; GLOBAL VARIABLES (CHANGE THESE!) ;;;;;;;;;
; title of the terminal window
; note - this script will do nothing if there is no matching window
; choose a uniquely identifiable substring of your terminal program's title
win_title = Bitvise xterm
; hotkey to open/hide/unhide
; choose from https://autohotkey.com/docs/KeyList.htm
hotkey = F12
; window resizing options
win_width_percent = 100 ; set to 0 to disable
win_height_percent = 50 ; set to 0 to disable
win_visible_transparency = 200 ; the transparency of the terminal window when it is visible 0 (transparent) through 255 (opaque)
;;;;;;;;; SCRIPT (DO NOT MODIFY) ;;;;;;;;;
SetTitleMatchMode, RegEx
Hotkey, %hotkey%, TheHotKey ; initialize the hotkey specified above
win_topleft_x := A_ScreenWidth * ((100 - win_width_percent)/2)/100 ; calculate the top left (x,y)
win_topleft_y := 0
win_height := A_ScreenHeight * (win_height_percent/100) ; calculate the window width, height
win_width := A_ScreenWidth * (win_width_percent/100)
currentWindow := 0
previousWindow := 0 ; so we can restore focus to previous window
loop { ; loop infinitely
WinGet, currentWindow, ID, A ; get the current active window
WinWaitNotActive, ahk_id %currentWindow% ; wait until that window is not active anymore
IfWinNotActive, %win_title% ; if our terminal window is no longer active (it was and then it was clicked out), make sure it's hidden
WinSet, Transparent, On, %win_title%
previousWindow := currentWindow ; so we can keep track of previous window
}
TheHotKey: ; setup our hotkey
IfWinExist, %win_title% ; ensure our window even exists
{
WinMove, %win_title%,, %win_topleft_x%, %win_topleft_y%, %win_width%, %win_height% ; make sure it's in the correct location and has correct size
IfWinNotActive, %win_title% ; if the window is not active and our hotkey was fired, let's show it
{
WinSet, Transparent, %win_visible_transparency%, %win_title%
WinActivate, %win_title%
}
Else ; if the window is active and our hotkey was fired, let's hide it and active the previous window
{
WinSet, Transparent, On, %win_title%
WinActivate, ahk_id %previousWindow%
}
}
return
@jamesb93
Copy link

I was lazy at first but then solved the issues myself on my fork of your gist. Thanks again for this super useful thing!

@juventus18
Copy link

Fantastic! I've been trying to figure this out to replace Cmder with the new Windows Terminal. Had a slight problem with the window not being 100% width despite being configured as such (it was 8px short on both sides). A little pixel-pushing and its just right. Thanks for doing the hard part!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment