Last active
October 14, 2024 22:07
-
-
Save pannal/437e7487bf7b33a4de4889be65675d03 to your computer and use it in GitHub Desktop.
REAPER Control v0.12b AutoHotkey Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ---------------------------------------------------------------------------------------------------------- | |
; _____ _____ _____ _____ _____ _____ _____ _ _ | |
; | __ || __|| _ || _ || __|| __ | | | ___ ___ | |_ ___ ___ | | | |
; | -|| __|| || __|| __|| -| | --|| . || || _|| _|| . || | | |
; |__|__||_____||__|__||__| |_____||__|__| |_____||___||_|_||_| |_| |___||_| | |
; | |
; ---------------------------------------------------------------------------------------------------------- | |
; REAPER Control | |
; panni | |
; 2018 | |
; v0.12b | |
; partly based on: | |
; | |
;; RunHidden | |
;; Fanatic Guru | |
;; 2014 08 28 | |
;; Version: 1.0 | |
;; | |
;; Script derived from and inspired by Coco at http://ahkscript.org/boards/viewtopic.php?f=5&t=4373 | |
; ---------------------------------------------------------------------------------------------------------- | |
; INTRODUCTION | |
; When called with the path to reaper.exe as first argument, automatically starts REAPER and manages it. | |
; If called without first argument the script waits for REAPER to appear and then manages it. | |
; | |
; For configuration options, see CONFIG below | |
; | |
; Features: | |
; - automatically attaches to or runs REAPER | |
; - automatically hides REAPER into the systray if autohide=1 | |
; - adds a persistent systray icon which toggles REAPER on doubleclick | |
; - systray icon has a menu which allows showing/hiding of REAPER, closing and restarting | |
; ---------------------------------------------------------------------------------------------------------- | |
; | |
; CONFIG | |
; | |
autorun = 1 ; Automatically runs REAPER if the first argument is given | |
autohide = 1 ; Automatically hides REAPER when REAPER is detected | |
minimize_check_interval = 500 ; How often to check whether REAPER is minimized, in milliseconds | |
; | |
; ENVIROMENT | |
; | |
#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. | |
#NoTrayIcon | |
#Persistent | |
DetectHiddenWindows On | |
SetWinDelay, 500 | |
Program = %1% | |
SplitPath, Program,,,,Title | |
Hwnd = -1 | |
version = 0.12b | |
; Setup Tray Menu | |
AddBaseTray() | |
Menu Tray, Tip, REAPER started`, waiting for it to load | |
; RUNTIME | |
; Run REAPER hidden if given; else wait for it to appear | |
if (!Program or !autorun) { | |
WinWait, ahk_class REAPERwnd | |
Hwnd := WinExist() | |
WinGet,PID,PID,ahk_id %Hwnd% | |
WinGet,Program,ProcessPath,ahk_id %Hwnd% | |
if autohide | |
SetHidden(Hwnd) | |
else | |
SetNotHidden(Hwnd) | |
WaitReaper() | |
} | |
else { | |
RunReaper() | |
WaitReaper() | |
} | |
; Subroutines | |
; Generic Tray click handler | |
TrayClick: | |
if Hwnd = -1 | |
return | |
if DllCall("IsWindowVisible", "Ptr", Hwnd) | |
{ | |
SetHidden(Hwnd) | |
} | |
else | |
{ | |
SetNotHidden(Hwnd) | |
} | |
return | |
; Tray close click handler | |
TrayCloseClick: | |
IfWinExist, ahk_class REAPERwnd | |
WinClose | |
ExitApp | |
return | |
; Tray close script click handler | |
TrayCloseScriptClick: | |
if Hwnd | |
SetNotHidden(Hwnd) | |
ExitApp | |
return | |
; Tray restart click handler | |
TrayRestartClick: | |
IfWinExist, ahk_class REAPERwnd | |
WinGet,fn,ProcessPath,ahk_id %Hwnd% | |
if fn | |
WinClose | |
Program = 0 | |
RunReaper(fn) | |
WaitReaper() | |
return | |
; Dummy click handler | |
empty: | |
return | |
; Run program | |
RunReaper(fn=0) { | |
global PID, Program, Hwnd, autohide | |
if (!Program and fn) | |
Program = %fn% | |
WorkingDir := SplitPath, Program,, dir | |
Run %Program%, %WorkingDir%, , PID | |
WinWait, ahk_class REAPERwnd | |
Hwnd := WinExist() | |
if autohide | |
Sleep, 1000 | |
SetHidden(Hwnd) | |
} | |
WaitReaper() { | |
global Hwnd | |
WinWaitForMinimized(Hwnd) | |
WinWaitClose, ahk_id %Hwnd% | |
ExitApp | |
} | |
; Set Hwnd hidden | |
SetHidden(Hwnd) { | |
AddBaseTray("hidden", Hwnd) | |
WinHide ahk_id %Hwnd% | |
return | |
} | |
; Set Hwnd shown (and restore it) | |
SetNotHidden(Hwnd) { | |
AddBaseTray("shown", Hwnd) | |
WinShow ahk_id %Hwnd% | |
WinRestore ahk_class REAPERwnd | |
WinActivate ahk_id %Hwnd% | |
return | |
} | |
; Core tray stuff | |
AddBaseTray(state=0, Hwnd=0) { | |
global PID, Program, version | |
Menu Tray, DeleteAll | |
Menu Tray, NoStandard | |
Menu Tray, Icon | |
Menu Tray, Icon, %Program% | |
if (Hwnd) { | |
Menu Tray, Add, REAPER Control v%version% (PID: %PID%), empty | |
Menu Tray, Disable, REAPER Control v%version% (PID: %PID%) | |
} | |
else { | |
Menu Tray, Add, REAPER Control v%version% (waiting), empty | |
Menu Tray, Disable, REAPER Control v%version% (waiting) | |
} | |
Menu Tray, Add | |
if (state) { | |
if (state = "hidden") | |
{ | |
Menu Tray, Add, Show REAPER, TrayClick | |
Menu Tray, Default, Show REAPER | |
Menu Tray, Tip, Show REAPER (PID: %PID%) | |
} | |
else | |
{ | |
Menu Tray, Add, Hide REAPER, TrayClick | |
Menu Tray, Default, Hide REAPER | |
Menu Tray, Tip, Hide REAPER (PID: %PID%) | |
} | |
} | |
if (Hwnd) { | |
Menu Tray, Add | |
Menu Tray, Add, Restart REAPER, TrayRestartClick | |
Menu Tray, Add, Close REAPER, TrayCloseClick | |
} | |
Menu Tray, Add | |
Menu Tray, Add, Close REAPER Control, TrayCloseScriptClick | |
} | |
; Window minimize "event" | |
WinWaitForMinimized(ByRef winID) { | |
global minimize_check_interval | |
loop | |
{ | |
WinGet,winMinMax,MinMax,ahk_id %winID% | |
if (!WinExist(ahk_class REAPERwnd)) | |
return | |
if (winMinMax = -1) | |
SetHidden(winID) | |
sleep %minimize_check_interval% | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script is great. But I had a question maybe you could solve. Everytime when I try and shut down my pc, reaper prevents it from shutting down. I have to then manually close reaper via de script because it asks to save the project thats open. Do you have any idea how I could prevent this from asking or from shutting down?
Thanks in advance.