Advertisement
anonymous1184

SwitchOrRun.ahk

Feb 8th, 2022
2,317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv
  2. #Warn All
  3. #WinActivateForce
  4.  
  5. EnvGet A_LocalAppData, LocalAppData
  6. EnvGet A_ProgramFilesX86, ProgramFiles(x86)
  7.  
  8. return ; End of auto-execute
  9.  
  10. 1::SwitchOrRun("- Word", "WINWORD.EXE")
  11. 2::MinimizeAll("WINWORD.EXE")
  12.  
  13. 3::SwitchOrRun("- Google Chrome", "chrome.exe")
  14. 4::MinimizeAll("chrome.exe")
  15.  
  16. 5::SwitchOrRun("- Visual Studio Code", A_LocalAppData "\Programs\Microsoft VS Code\Code.exe")
  17. 6::MinimizeAll("code.exe")
  18.  
  19. 7::SwitchOrRun("Mendeley Desktop", A_ProgramFilesX86 "\Mendeley Desktop\MendeleyDesktop.exe")
  20. 8::MinimizeAll("MendeleyDesktop.exe")
  21.  
  22. ; Functions
  23.  
  24. MinimizeAll(ExeName)
  25. {
  26.     DetectHiddenWindows Off
  27.     WinGet wList, List, % "ahk_exe " ExeName
  28.     loop % wList
  29.         WinMinimize % "ahk_id " wList%A_Index%
  30. }
  31.  
  32. SwitchOrRun(WinTitle, Path)
  33. {
  34.     SetTitleMatchMode 2
  35.     SplitPath Path, ExeName
  36.     if !WinExist(WinTitle " ahk_exe " ExeName) {
  37.         Run % Path,, UseErrorLevel
  38.         if (ErrorLevel) {
  39.             MsgBox 0x10, Error, % "Path not found: " Path
  40.             return
  41.         }
  42.     }
  43.     WinActivate % WinTitle
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement