Skip to content

Instantly share code, notes, and snippets.

@niclaslindstedt
Last active October 25, 2018 07:12
Show Gist options
  • Save niclaslindstedt/c993f247c8f38787df9c67afe3441291 to your computer and use it in GitHub Desktop.
Save niclaslindstedt/c993f247c8f38787df9c67afe3441291 to your computer and use it in GitHub Desktop.
Useful Kodi AutoHotKey Binds
; Start Program
; If Program is already started, maximize and focus its window.
; If Program is started but minimized, maximize it.
; If Program is not started, start it.
ActivateProgram(name, executable, path)
{
Process,Exist,%executable%
If Errorlevel != 0 ;Errorlevel returns pid of process
{
IfWinNotActive,%name%
{
SplashTextOn,,,Focusing %name%
Sleep,1000
SplashTextOff
WinActivate,%name%
Return
}
IfWinActive,%name%
{
WinMinimize,%name%
SplashTextOn,,,%name% minimized
Sleep,1000
SplashTextOff
Return
}
}
SplashTextOn,,,Starting %name%
Sleep,1000
SplashTextOff
Run,%path%
Sleep,1000
WinActivate,%name%
Return
}
; Kill Program
; Kill the process of a running program
KillProgram(name, executable)
{
Process,Exist,%executable%
If Errorlevel != 0 ;Errorlevel returns pid of process
{
SplashTextOn,,,Force-exiting %name% (pid %Errorlevel%)
Sleep,1000
SplashTextOff
Process,Close,%executable%
Return
}
SplashTextOn,,,%name% not running
Sleep,1000
SplashTextOff
Return
}
; Close XBMC Application
; If XBMC Application is focused, try shutting down using the shutdown menu (and then minimize).
; If XBMC Application is not focused, then kill process.
CloseXBMC(name, executable)
{
IfWinActive,%name%
{
Send s
Sleep,500
Send {End}
Sleep,100
Send {Enter}
WinMinimize,%name%
Return
}
IfWinNotActive,%name%
{
KillProgram(%name%, %executable%)
}
}
^+z::
CloseXBMC("Kodi", "Kodi.exe")
Return
^+x::
ActivateProgram("Kodi", "Kodi.exe", "C:\Program Files (x86)\Kodi\kodi.exe")
Return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment