I apologize if this is not the right forum. I have a video capture program that I have launched at startup, but I would like to have it minimized to system tray when it launches. The program has no such option in its settings unfortunately. Given how many incredible and complex things autohotkey seems capable of, I figured there is probably a way to do this.
The program is located at -- C:\Program Files (x86)\NCH Software\debut.exe
Sorry for being such a noob and programming moron, I tried but couldn't figure it out myself. Any help would be greatly appreciated -- thanks in advance!!
Need script to always start program in system tray
Re: Need script to always start program in system tray
This is possible, using a combination of WinHide/WinShow + Shell_NotifyIcon. Haven't tested this yet but you might have to specify a dummy window (perhaps the script's window) for Shell_NotifyIcon -> script receives notification messages(on icon click, hover etc.) then perform the necessary task on the icon and the target window (video capture program).
Re: Need script to always start program in system tray
Okay -- I tried this, which I got from the WinHide page here: http://www.autohotkey.com/docs/commands/WinHide.htmCoco wrote:This is possible, using a combination of WinHide/WinShow + Shell_NotifyIcon. Haven't tested this yet but you might have to specify a dummy window (perhaps the script's window) for Shell_NotifyIcon -> script receives notification messages(on icon click, hover etc.) then perform the necessary task on the icon and the target window (video capture program).
Run, debut.exe
WinWait, Debut Video Capture Software
Sleep, 500
WinHide ; use the window found above
Sleep, 1000
WinShow
This does hide the window at first, then the window comes back up and the script is terminated. What am I doing wrong? I want the window to stay hidden until I click on it in the system tray. Is this possible at all?
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Need script to always start program in system tray
There could be something odd about your program where it has like a splash screen then another window opens which it forces to the front. I don't know.noylopa wrote:Okay -- I tried this, which I got from the WinHide page here: http://www.autohotkey.com/docs/commands/WinHide.htmCoco wrote:This is possible, using a combination of WinHide/WinShow + Shell_NotifyIcon. Haven't tested this yet but you might have to specify a dummy window (perhaps the script's window) for Shell_NotifyIcon -> script receives notification messages(on icon click, hover etc.) then perform the necessary task on the icon and the target window (video capture program).
Run, debut.exe
WinWait, Debut Video Capture Software
Sleep, 500
WinHide ; use the window found above
Sleep, 1000
WinShow
This does hide the window at first, then the window comes back up and the script is terminated. What am I doing wrong? I want the window to stay hidden until I click on it in the system tray. Is this possible at all?
But for Notepad as an example you can do this:
Code: Select all
Run, NotePad.exe,,Min
Also it is important to understand that WinHide, hides a window which is different than minimizing it. It is hidden from the user in most normal ways and not just minimized to the taskbar. It is not in the taskbar, tray icons, applications list, etc. It is kind of like a hidden system's file on your computer. A window that the operating system believes a general user should never needs to interact with. You can still see it in the processes list though.
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Re: Need script to always start program in system tray
Code: Select all
Run, NotePad.exe,,Min
Re: Need script to always start program in system tray
ozzii wrote:This is minimizing the window but not in the system stray. At least if the app doesn't include this function already (something like 'put in system tray if minimized').Code: Select all
Run, NotePad.exe,,Min
Debut doesn't have that function, which is why I was asking if maybe there was a way to use AHK to force the app into the system tray when minimized. Minimizing on startup in Windows is easy enough with a properly configured shortcut, but forcing the app into the system tray when minimized requires third-party assistance. I could use something like TrayIt, but I already have AHK setup with some other handy scripts so I thought maybe I could just use AHK for this as well.
But thanks anyway!
Re: Need script to always start program in system tray
We can totally forget about Shell_NotifyIcon. The trick is for the script to run your app hidden and then to use the script's tray icon as a dummy to act as the app's icon. You'll basically use the script to launch your app. Below is sample script using notepad, try double clicking on the tray icon -> it'll show/hide notepad:
Code: Select all
#NoTrayIcon
#Persistent
global hNotepad
/* Setup Tray icon and add item that will handle
* double click events
*/
Menu Tray, Icon
Menu Tray, Icon, notepad.exe
Menu Tray, Add, Show / Hide Notepad, TrayClick
Menu Tray, Default, Show / Hide Notepad
;// Run notepad hidden
DetectHiddenWindows On
Run Notepad,, Hide, PID
WinWait ahk_pid %PID%
hNotepad := WinExist()
DetectHiddenWindows Off
return
TrayClick:
OnTrayClick()
return
;// Show / hide notepad on double click
OnTrayClick() {
if DllCall("IsWindowVisible", "Ptr", hNotepad) {
WinHide ahk_id %hNotepad%
} else {
WinShow ahk_id %hNotepad%
WinActivate ahk_id %hNotepad%
}
}
Re: Need script to always start program in system tray
That looks awesome!! Just what I was looking for!
I'm on my work computer and it works perfectly with notepad -- will try this at home tonight with Debut and see if I can match this behavior with that app.
-----
I just tried replicating this script with Calculator on my Win 7 work machine -- just as a test to see if anything else beside the app name needed to be changed-- and I wasn't able to get the tray icon to display.
Here is the script taken from the Notepad script you sent, with 'Notepad' replaced with 'Calculator' wherever possible.
#NoTrayIcon
#Persistent
global hCalculator
/* Setup Tray icon and add item that will handle
* double click events
*/
Menu Tray, Icon
Menu Tray, Icon, calc.exe
Menu Tray, Add, Show / Hide Calculator, TrayClick
Menu Tray, Default, Show / Hide Calculator
;// Run calculator hidden
DetectHiddenWindows On
Run Calculator,, Hide, PID
WinWait ahk_pid %PID%
hCalculator := WinExist()
DetectHiddenWindows Off
return
TrayClick:
OnTrayClick()
return
;// Show / hide calculator on double click
OnTrayClick() {
if DllCall("IsWindowVisible", "Ptr", hCalculator) {
WinHide ahk_id %hCalculator%
} else {
WinShow ahk_id %hCalculator%
WinActivate ahk_id %hCalculator%
}
}
When I tried this I got this error -- see attached.
Any ideas?
I'm on my work computer and it works perfectly with notepad -- will try this at home tonight with Debut and see if I can match this behavior with that app.
-----
I just tried replicating this script with Calculator on my Win 7 work machine -- just as a test to see if anything else beside the app name needed to be changed-- and I wasn't able to get the tray icon to display.
Here is the script taken from the Notepad script you sent, with 'Notepad' replaced with 'Calculator' wherever possible.
#NoTrayIcon
#Persistent
global hCalculator
/* Setup Tray icon and add item that will handle
* double click events
*/
Menu Tray, Icon
Menu Tray, Icon, calc.exe
Menu Tray, Add, Show / Hide Calculator, TrayClick
Menu Tray, Default, Show / Hide Calculator
;// Run calculator hidden
DetectHiddenWindows On
Run Calculator,, Hide, PID
WinWait ahk_pid %PID%
hCalculator := WinExist()
DetectHiddenWindows Off
return
TrayClick:
OnTrayClick()
return
;// Show / hide calculator on double click
OnTrayClick() {
if DllCall("IsWindowVisible", "Ptr", hCalculator) {
WinHide ahk_id %hCalculator%
} else {
WinShow ahk_id %hCalculator%
WinActivate ahk_id %hCalculator%
}
}
When I tried this I got this error -- see attached.
Any ideas?
Re: Need script to always start program in system tray
Try replacing Run Calculator with Run calc.exe
Re: Need script to always start program in system tray
That did it!!Coco wrote:Try replacing Run Calculator with Run calc.exe
I'm so gonna make this work at home -- thank you!!
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Need script to always start program in system tray
This is an interesting idea (run a regular program hidden, with a tray icon to toggle it hidden and unhidden). I don't have a use for it at the moment but it seems like something that could be useful in the future if I had a script to do it easily.Coco wrote:We can totally forget about Shell_NotifyIcon. The trick is for the script to run your app hidden and then to use the script's tray icon as a dummy to act as the app's icon. You'll basically use the script to launch your app. Below is sample script using notepad, try double clicking on the tray icon -> it'll show/hide notepad:Code: Select all
#NoTrayIcon #Persistent global hNotepad /* Setup Tray icon and add item that will handle * double click events */ Menu Tray, Icon Menu Tray, Icon, notepad.exe Menu Tray, Add, Show / Hide Notepad, TrayClick Menu Tray, Default, Show / Hide Notepad ;// Run notepad hidden DetectHiddenWindows On Run Notepad,, Hide, PID WinWait ahk_pid %PID% hNotepad := WinExist() DetectHiddenWindows Off return TrayClick: OnTrayClick() return ;// Show / hide notepad on double click OnTrayClick() { if DllCall("IsWindowVisible", "Ptr", hNotepad) { WinHide ahk_id %hNotepad% } else { WinShow ahk_id %hNotepad% WinActivate ahk_id %hNotepad% } }
I believe I will fool around with rewriting this to be more general. Maybe a script that uses command line parameters to run other programs in hidden mode.
Thanks for the idea Coco.
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Re: Need script to always start program in system tray
Like you said FanaticGuru this is an interesting idea.
I will keep this for a later use.
Thanks Coco
I will keep this for a later use.
Thanks Coco
Re: Need script to always start program in system tray
Problem with this:
When you first start the script it's ok.
But if you close notepad, the icon stay on the tray witout any possibility to do anything with it.
When you first start the script it's ok.
But if you close notepad, the icon stay on the tray witout any possibility to do anything with it.
Re: Need script to always start program in system tray
You can use WinWaitClose to detect this and automatically quit the script
Code: Select all
#NoTrayIcon
#Persistent
global hNotepad
/* Setup Tray icon and add item that will handle
* double click events
*/
Menu Tray, Icon
Menu Tray, Icon, notepad.exe
Menu Tray, Add, Show / Hide Notepad, TrayClick
Menu Tray, Default, Show / Hide Notepad
;// Run notepad hidden
DetectHiddenWindows On
Run Notepad,, Hide, PID
WinWait ahk_pid %PID%
hNotepad := WinExist()
WinWaitClose ahk_id %hNotepad%
MsgBox,,, Notepad was closed. Quitting script.., 1
ExitApp
TrayClick:
OnTrayClick()
return
;// Show / hide notepad on double click
OnTrayClick() {
if DllCall("IsWindowVisible", "Ptr", hNotepad) {
WinHide ahk_id %hNotepad%
} else {
WinShow ahk_id %hNotepad%
WinActivate ahk_id %hNotepad%
}
}
Re: Need script to always start program in system tray
@ozzii, regarding the Notepad example, you can further extend it by:
- Adding context sensitive hotkeys/hotstrings to provide simple auto-complete for notepad
- Run AHK code entered in notepad (using DynaRun())
- Add custom items to the tray menu
- etc..
Last edited by Coco on 27 Aug 2014, 08:11, edited 1 time in total.
Re: Need script to always start program in system tray
Haha Very interesting examples, i see here!
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Need script to always start program in system tray
Here is my generic version that uses command parameters.
RunHidden
FG
RunHidden
Code: Select all
; 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
;
; Run program with hidden window
; Program can be toggled between hidden and shown by tray menu icon
;
;{-----------------------------------------------
; Designed to have path and/or name of program passed as a command parameter
; Example for Notepad.exe
; Create shortcut to RunHidden script
; In properties of shortcut put Notepad.exe at very end of Target field as a command parameter
; "D:\Users\Guru\Documents\AutoHotkey\My Scripts\RunHidden.ahk" Notepad.exe
; The program to run in hidden mode could include the entire path in the command parameter if needed
; "D:\Users\Guru\Documents\AutoHotkey\My Scripts\RunHidden.ahk" C:\Windows\System32\Notepad.exe
; The script gets the file title out of the full path for display purposes in the menu tray
;}
; INITIALIZATION - 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
;}
; INITIALIZATION - VARIABLES
;{-----------------------------------------------
;
Program = %1%
SplitPath, Program,,,,Title
;}
; INITIALIZATION - GUI
;{-----------------------------------------------
;
; Setup Tray Menu
Menu Tray, DeleteAll
Menu Tray, NoStandard
Menu Tray, Icon
Menu Tray, Icon, %Program%
Menu Tray, Add, Show %Title%, TrayClick
Menu Tray, Default, Show %Title%
Menu Tray, Tip, %Title%
;}
; AUTO-EXECUTE
;{-----------------------------------------------
;
; Run Program hidden
Run %Program%,, Hide, PID
WinWait ahk_pid %PID%
Hwnd := WinExist()
WinWaitClose ahk_id %Hwnd%
ExitApp
;
;}-----------------------------------------------
; END OF AUTO-EXECUTE
; SUBROUTINES - GUI
;{-----------------------------------------------
;
; Show / Hide Program on Doubleclick
TrayClick:
if DllCall("IsWindowVisible", "Ptr", Hwnd)
{
Menu Tray, DeleteAll
Menu Tray, Add, Show %Title%, TrayClick
Menu Tray, Default, Show %Title%
WinHide ahk_id %Hwnd%
}
else
{
Menu Tray, DeleteAll
Menu Tray, Add, Hide %Title%, TrayClick
Menu Tray, Default, Hide %Title%
WinShow ahk_id %Hwnd%
WinActivate ahk_id %Hwnd%
}
return
;}
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Re: Need script to always start program in system tray
Thanks FanaticGuru
Who is online
Users browsing this forum: mikeyww and 310 guests