EDIT: This could maybe be moved in Tutorials
This is my simple way of starting/toogling Apps Quicly - Including quick Google Chrome WebApps.
What's really interesting is how you can start it in a smart way to toogle or start quickly your favorite pgrms or ... Google chrome web apps
(Yeah that's what I really like as I figured out the parameter "--app" to do it! )
With web apps it means you can toogle or start every website as an external app having its own window/icon.
The second interesting thing IMHO is the single hotkey example to start your subroutine or menu.
See at bottom for examples
By Toogling I mean : if the window exist then it is brought to foreground. If it is already in foreground it is Minimized (although this won't be of much use except with single hotkey).
If it is not found then the program is started with optional parameters.
It relies on a simple function to Toogle a window based on some Wintitle parts and the .exe process OR Start the .exe with some parameters :
ToogleOrStart Function
Code: Select all
; T O O G L E O R S T A R T P G R M
;-------------------------------------------------------------------------------
;ToogleOrStart(PgrmProcessPathorName,WindowPartTitle="",ExeCommands="")
;***************************************************************************************
;PgrmProcessPathorName : ex : Notepad or Notepad.exe or C:\Program Files (x86)\....process.exe
;------------------------------------
;(Optional)WindowPartTitle : Some parts of the title of the window you want to toogle. e.g: "- Notepad"
;This is mainly useful in case you want to toogle or start a specific window of your program.
;Ex : with Chrome apps, the exe will always be Chrome.exe but you can detect if the specific website is opened using WindowPartTitle
;------------------------------------
;(Optional)ExeCommands : Some ex commands to start the pgrm in case it was not detected
;We use it in these examples to start web apps : e.g.: "--app=http://www.website.com"
;------------------------------------
ToogleOrStart(PgrmProcessPathorName,WindowPartTitle="",ExeCommands="")
{
SetTitleMatchMode 2
global CWindow, CProcessName
global FastMenuStarted
if FastMenuStarted!=1 ;For use with a contextmenu , see below in original post
{
WinGetTitle, CWindow, A
WinGet, CProcessName, ProcessName, A
}
if InStr(PgrmProcessPathorName, "\")
SplitPath, PgrmProcessPathorName , PgrmProcess
else
PgrmProcess:=PgrmProcessPathorName
if (SubStr(PgrmProcess,-3)!=".exe")
PgrmProcess.=".exe"
IfWinExist, %WindowPartTitle% ahk_exe %PgrmProcess%
{
if (CProcessName=PgrmProcess && InStr(CWindow,WindowPartTitle))
{
WinMinimize, %WindowPartTitle% ahk_exe %PgrmProcess%
}
else
{
WinActivate, %WindowPartTitle% ahk_exe %PgrmProcess%
}
}
else
Run % PgrmProcessPathorName . " " ExeCommands
FastMenuStarted= ;For use with a contextmenu
}
Somewhere in your code to Toogle or Start you have to call the function
e.g. For Notepad, simply use :
Code: Select all
ToogleOrStart("Notepad")
;or
;ToogleOrStart("Notepad.exe")
Code: Select all
ToogleOrStart("C:\Program Files\CustomSoftware.exe")
e.g. For Toogling a new Notepad (untitled) or starting one that could be :
Code: Select all
ToogleOrStart("Notepad","Untitled")
Now let's say you want to Toogle or start some music at 8tracks.com as a web app (I'm sure many of you could be interested by using it for Facebook and many other web apps)
You can use :
Code: Select all
ToogleOrStart("chrome.exe","8tracks","--app=http://8tracks.com/login")
Here are some ideas:
We will start by the simpliest way with a standard hotkey, which I quite DISlike.
EXAMPLE WITH HOTKEY: CTRL + SHIFT + T
Code: Select all
^+t::Gosub Toogle8tracks
Toogle8tracks:
ToogleOrStart("chrome.exe","8tracks","--app=http://8tracks.com/login")
return
EXAMPLE WITH SINGLE KEY HOTKEY !!!
This will start 8tracks as a web app by simply holding down the "_" key (This is the 8 at top of my French Keyboard, that's why )
!WARNING! THESE SINGLE KEY HOTKEYS TEND TO SLOW DOWN THE USED KEY A BIT AND LONG PRESS FOR FAST REAPEAT WON'T WORK ANYMORE
SO I SUGGEST YOU JUST USE SPECIAL KEYS SUCH AS THE ONE ON TOP OF KEYBOARDS OR SPECIAL CHARACTERS
EXAMPLE WITH LONG "_" KEY PRESS
IF YOU CHANGE THE HOTKEY YOU NEED TO MODIFY IT IN 4 PLACES : The Hotkey label the 2 KeyWait and the SendInput
Code: Select all
;----------------------------------------
;8tracks by "_" (8) long
;IF YOU CHANGE THE HOTKEY YOU NEED TO MODIFY IT IN 4 PLACES
;----------------------------------------
$_::
KeyWait, _, T0.5
If (ErrorLevel=1) {
ToogleOrStart("chrome.exe","8tracks","--app=http://8tracks.com/login")
KeyWait, _
}
Else {
SendInput _
}
Return
EXAMPLE WITH A CONTEXT MENU
STARTED BY CTRL+SHIFT+T (but could be single key hotkey as well!!)
Code: Select all
FastPgrmMenu()
FastPgrmMenu()
{
Menu, FastPgrmMenu, Add, Firefox, Firefox
Menu, FastPgrmMenu, Add, 8tracks, Toogle8tracks
Menu, FastPgrmMenu, Add, Notepad, Notepad
}
^+t::
global CWindow,CProcessName,FastMenuStarted
WinGetTitle, CWindow, A
WinGet, CProcessName, ProcessName, A
FastMenuStarted=1
Menu, FastPgrmMenu, Show
return
Firefox:
ToogleOrStart("Mozilla Firefox", "firefox.exe")
Return
Notepad:
ToogleOrStart("Notepad")
Return
Toogle8tracks:
ToogleOrStart("chrome.exe","8tracks","--app=http://8tracks.com/login")
return
Don't hesitate to comment for ideas and related things