Advertisement
DuskDegree9667

AutoHotkey Profile Manager (Replaces apps like Corsair iCUE, Razer Synapse, Logitech G HUB, etc)

Jun 25th, 2025 (edited)
1,910
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Profile Manager
  2. ; Monitors active applications and switches AutoHotkey profiles accordingly
  3.  
  4. #NoEnv
  5. #SingleInstance Force
  6. #Persistent
  7.  
  8. ; Configuration
  9. ScriptsPath := "C:\Users\user\AutoHotkey\"
  10. CheckInterval := 500  ; Check every 0.5 second(s)
  11.  
  12. ; Global variables
  13. CurrentProfile := ""
  14. CurrentScriptPID := 0
  15. LastActiveProcess := ""
  16.  
  17. ; Application to script mapping
  18. AppProfiles := {}
  19.  
  20. ; Application Group 1
  21. AppProfiles["iTunes.exe"] := "AHK_iTunes.ahk" ; Example ⸺ AHK_iTunes.ahk is in another pasted script, and includes dual-layer functionality and infinite mouse wheel scrolling
  22.  
  23. ; Application Group 2
  24. AppProfiles["App1.exe"] := "Profile1.ahk"
  25. AppProfiles["App2.exe"] := "Profile2.ahk"
  26.  
  27. ; Application Group 3
  28. AppProfiles["App7.exe"] := "Profile7.ahk"
  29. AppProfiles["App8.exe"] := "Profile8.ahk"
  30.  
  31. ; Start monitoring
  32. SetTimer, CheckActiveWindow, %CheckInterval%
  33.  
  34. CheckActiveWindow:
  35.    WinGet, ActiveProcess, ProcessName, A
  36.    
  37.     ; Only check if the process actually changed (performance optimization)
  38.     if (ActiveProcess != LastActiveProcess) {
  39.         LastActiveProcess := ActiveProcess
  40.        
  41.         ; Determine which profile to use
  42.         TargetScript := AppProfiles[ActiveProcess]
  43.         if (!TargetScript) {
  44.             TargetScript := "DesktopProfile.ahk"  ; Default fallback
  45.         }
  46.        
  47.         ; Switch profile if different from current
  48.         if (TargetScript != CurrentProfile) {
  49.             SwitchToProfile(TargetScript)
  50.         }
  51.     }
  52. return
  53.  
  54. SwitchToProfile(ScriptName) {
  55.     global ScriptsPath, CurrentScriptPID, CurrentProfile
  56.     ; Don't kill the Profile Manager itself
  57.     ProfileManagerPID := DllCall("GetCurrentProcessId")
  58.     if (CurrentScriptPID > 0 && CurrentScriptPID != ProfileManagerPID) {
  59.         Process, Close, %CurrentScriptPID%
  60.         CurrentScriptPID := 0
  61.     }
  62.  
  63.     ; Don't relaunch the same profile
  64.     if (ScriptName = CurrentProfile)
  65.         return
  66.  
  67.     ; Launch new profile script
  68.     FullPath := ScriptsPath . ScriptName
  69.     if (FileExist(FullPath)) {
  70.         Run, "%A_AhkPath%" "%FullPath%", , , NewPID
  71.         CurrentScriptPID := NewPID
  72.         CurrentProfile := ScriptName
  73.         ; Optional: Show tray tip for debugging
  74.         ; TrayTip, Profile Manager, Switched to: %ScriptName%, 1, 1
  75.     } else if (ScriptName != "DesktopProfile.ahk") {
  76.         ; Only fall back to Desktop if not already trying Desktop
  77.         SwitchToProfile("DesktopProfile.ahk")
  78.     }
  79. }
  80.  
  81. ; Cleanup on exit
  82. OnExit, CleanupAndExit
  83.  
  84. CleanupAndExit:
  85.    if (CurrentScriptPID > 0) {
  86.         Process, Close, %CurrentScriptPID%
  87.     }
  88. ExitApp
  89.  
  90. ; Hotkey to manually reload ProfileManager (optional)
  91. ^!r::Reload
  92.  
  93. ; Hotkey to show current profile (optional for debugging)
  94. ^!p::
  95.     TrayTip, Profile Manager, Current Profile: %CurrentProfile%, 2, 1
  96. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement