;;; RunHide v0.5 bLisTeRinG 2004 #Persistent #SingleInstance off ;;; Add excluded apps after PPPshar rExc = PPPshar, ;#Z:: ;msgbox, LeftWIN + Z ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; When booting up allow more time. SplitPath, A_ScriptName,,,,rIni rIni = %A_ScriptDir%\%rIni%.ini ;msgbox, %rIni% rTTO = 4 iniRead, rTSO, %rIni%, options, TimeSinceOpen If a_TickCount < %rTSO% { iniRead, rTTO, %rIni%, options, TimeToOpen ;rTTO = 33 ;Tooltip, Time since Booting up system:`t%a_TickCount% ms`nWait for Application to Open:`t%rTTO%000 ms } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Sort Input rIn = %0% If rIn <> 0 { rApp = %1% IfGreater, rIn, 2 { ;;; 4th & 3rd parameters? IfGreater, rIn, 4 { rFSpec = %5% ;rTTO = %5% } IfGreater, rIn, 3 { rName = %4% } rOpt = %3% IfExist, %2% { rPath = %2% IfExist, %2%\%rApp% { rApp = %2%\%rApp% } If rName = , { SplitPath, rApp, , , ,rName } } Else { rName = %2% SplitPath, rApp, , rPath } IfEqual, rOpt, close { rApp = GoSub rClose Return } IfEqual, rOpt, show { GoSub rShow Return } If rOpt in max,min,hide { GoSub rRun Return } } ;;; 2 parameters IfGreater, rIn, 1 { rPath = %2% IfEqual, rPath, close { rOpt = %rPath% SplitPath, rApp, , rPath SplitPath, rApp, , , ,rName GoSub rClose Return } IfEqual, rPath, show { rOpt = %rPath% SplitPath, rApp, , rPath SplitPath, rApp, , , ,rName GoSub rShow Return } If rPath in max,min,hide { rOpt = %rPath% SplitPath, rApp, , rPath SplitPath, rApp, , , ,rName GoSub rRun Return } IfNotExist, %rPath% { rName = %2% SplitPath, rApp, , rPath } Else { SplitPath, rApp, , , ,rName } rOpt = Hide GoSub rRun Return } ;;; 1 parameter Else { SplitPath, 1, , rPath rOpt = Hide SplitPath, rApp, , , ,rName GoSub rRun Return } } ;;; 0 parameters Else { GoSub rGetFile Return } Return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; The routines rClose: DetectHiddenWindows, On SetTitleMatchMode, 2 IfWinExist, %rName% { WinClose, %rName%, , 0 IfWinExist, %rName% { WinKill, %rName%, , 0 } Menu, tray, deleteall Menu, tray, add, &Open %rName%, rRun Menu, tray, default, &Open %rName% Menu, tray, add, &New, rGetFile Menu, tray, add, &Help, rHelp Menu, tray, add, E&xit, rExit } Else { GoSub rFail } Return rExit: DetectHiddenWindows, On SetTitleMatchMode, 2 IfWinExist, %rName% { DetectHiddenWindows, Off IfWinNotExist, %rName% { DetectHiddenWindows, On WinRestore, %rName% WinActivate, } MsgBox, 3, Exit RunHide, Unload %rName%?, 5 IfMsgBox, yes, GoSub rClose IfMsgBox, cancel, Return IfMsgBox, TIMEOUT, GoSub rClose } Tooltip, ExitApp rFail: MsgBox, 0, Titlebar text search failed!,`n`n`t`t"%rName%"`n`n Not found in any Titlebar window currently open.,7 ExitApp Return rGetFile: rOpt = Hide FileSelectFile, rApp, 1, %windir%, Select an Application to RunHide., *.exe;*.lnk;*.com;*.ahk;*.bat;*.btm IfEqual, ErrorLevel, 1, ExitApp SplitPath, rApp, , rPath SplitPath, rApp, , , , rName GoSub rRun Return rGetName: ;; No matching Titlebar text - Check for rName in History. Loop, 10 { iniRead, rHist%a_index%, %rIni%, history,%a_index% StringTrimRight, rHistX, rHist%a_index%, 0 If rHistX = { break } If rHistX contains %rName% { StringGetPos, r, rHist%a_index%, | StringLeft, rName, rHist%a_index%,%r% r = ; MsgBox, rHistX: %rHistX%`nnewname %rName% break } } IfWinExist, %rName% { Return } ;; Not in History - Ask the user. InputBox, rName, This is some Titlebar Text, Window not found/loaded yet!`n`nOk to try again or... `n enter text seen in the Titlebar of: %rApp%`n`nTimeToOpen%rTTO%`tTimeSinceBoot%a_TickCount%`n,,320,240,,,,,%rName% If ErrorLevel = 1 { GoSub rHelp } IfWinExist, %rName% { ;; Put new matching rName and rApp in History. Loop, 10 { StringTrimRight, rHistX, rHist%a_index%, 0 If rHistX in ,ERROR, { rHist%a_index% = %rName%|%rApp% iniWrite, %rName%|%rApp%, %rIni%, history,%a_index% break ; The end of the array has been reached. } } Return } Goto rGetName rHelp: MsgBox, 1, RunHide Help, [path]RunHide.exe App [Path|Text] [Command] [Text]`n`n1: Application to Run - %rOpt%`n %rApp%`n`n2: Path ("." = current) or Titlebar Text (Close/Show)`n %rPath%`n`n3: Hide Min Max Show(toggle) or Close`n %rOpt%`n`n4: Titlebar text`n %rName%`n`n`%1:%1%`n`%2:%2%`n`%3:%3%`n`%4:%4%`n`%5:%5% IfMsgBox, ok, Return Goto rExit rIcon: SplitPath, rApp, , , rExt IfExist, %rPath%\%rName%.ico { rIcon = %rPath%\%rName%.ico } IfEqual, rIcon, { If rExt in pif,cmd,bat,btm { rIcon = %windir%\System\shell32.dll rIco = 66 } If rExt in lnk { ;rVerb = open rIcon = %windir%\System\shell32.dll rIco = 3 } If rExt = exe { ;;; Excluded apps. If rName in %rExc% { MsgBox, 1, , %rExt% %rPath%\%rName%.ico IfMsgBox, cancel, Return } Else { rIcon = %rApp% } } } IfEqual, rIcon, { RegRead, rKey, HKCR, .%rExt% RegRead, rIcon, HKCR, %rKey%\DefaultIcon StringRight, rIco, rIcon, 1 rIco++ StringTrimRight, rIcon, rIcon, 2 } ;;; MsgBox, 1, , Extension:%rExt%`nRegistryKey%rKey%`nIconFile:%rIcon%`nIconNumber:%rIco% ifmsgbox, cancel, return If rIcon = , { Return } Menu, tray, Icon, %rIcon%, %rIco% rIco = rIcon = rKey = Return rRun: IfExist, %rApp% { GoSub rIcon } ;;; MsgBox, %rVerb% %rApp% %rFSpec% %rPath% %rOpt% `n%rName% %rIn% ;;; DetectHiddenWindows, On SetTitleMatchMode, 2 rrr = %rApp% %rFSpec% Run, %rrr%, %rPath%, %rOpt% WinWait, %rApp%, , %rTTO% IfWinExist, %rName% { ;;; MsgBox, WinExists %rName% } Else { ;;; MsgBox, WinExistsNot %rName% GoSub rGetName } Menu, tray, NoStandard Menu, tray, deleteall Menu, tray, add, &Show %rName%, rShow Menu, tray, add, &Close %rName%, rClose Menu, tray, default, &Show %rName% Menu, tray, add, &Help, rHelp Menu, tray, add, E&xit, rExit If rOpt <> show { Menu, tray, show } Return rShow: ;;; MsgBox, %rApp% %rPath% %rOpt% %rName% DetectHiddenWindows, On SetTitleMatchMode, 2 IfWinExist, %rName% { DetectHiddenWindows, Off IfWinNotExist, %rName% { DetectHiddenWindows, On WinRestore, %rName% WinActivate, } Else { DetectHiddenWindows, On WinHide, %rName% } } Else { GoSub rRun } Return /* --------------------- When using menu-icons --------------------- 1) With icon-less applications, ahk can't cope, how can i check first? Fix: a) filter for exe vs bat,com,pif,lnk then apply system icon instead. what about chk registry? b) filter out known apps eg PPPshare.exe -use an iniFile? 2) Getting icons from DLLs is unpredictable using 'iconFile,iconNum' (wrong icon selected). Fix: a) Use something better than IrfanView as it counts each resolution as an icon. b) When getting DefaultIcon from the registry convert from 0... to 1... that is add one eg: iconNumber++ 3) There is the business of the low-colour 'notification area' -it looks crappy. ------------- Sharing menus ------------- 1) What if i want to add to a menu that was created by a previous AHK process? 2) I can't name my Menu anything but "tray", -submenus are fine though. Does this cause multiple menus any trouble? ie all the same name. */