Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

How do I WinActivate program running in system tray?


  • Please log in to reply
6 replies to this topic
Ron7
  • Guests
  • Last active:
  • Joined: --
Hi,
I'm brand new to AHK. I am using hotkeys to fire up programs if not running, and bring to the front if they are. Like this:
#o::
IfWinExist Outlook
{
    WinActivate
}
else
{
    Run %A_ProgramFiles%\Microsoft Office\OFFICE14\OUTLOOK.EXE
    WinWait Outlook
    WinActivate
}
Return
which works great. Now I'd like to do the same to a program (IM type called SPARK) that typically starts up and lives minimized in the system tray (lower right) until you click on it. Then when you close it it goes back to just the tray but is still running.

If it's running in the tray, I'd like to open the window and bring it front. If it's already open in a window (not necessarily maximized, just in an open window) then I just want to bring it to the front, and of it's neither I just want to start it because I can set it so it doesn't start minimized in the tray. I've tried the code above and it doesn't seem to work.
Any help would be appreciated.

nukchebi0
  • Members
  • 6 posts
  • Last active: Jun 23 2012 12:12 AM
  • Joined: 23 Jun 2012
Try consulting this thread: <!-- l --><a class="postlink-local" href="http://www.autohotkey.com/community/viewtopic.php?t=8999">viewtopic.php?t=8999</a><!-- l -->

Ron7
  • Members
  • 3 posts
  • Last active: Jun 25 2012 07:21 PM
  • Joined: 25 Jun 2012
Thanks. That seemed at first to be what I needed, but it's not working for me. I'm using this code
#s::
DetectHiddenWindows, Off
Process, Exist, Spark.exe
IfWinNotExist Spark ahk_pid %ErrorLevel%
{
WinShow, Spark ahk_pid %ErrorLevel%
WinActivate, Spark ahk_pid %ErrorLevel%
}
Else
IfWinExist Spark ahk_pid %ErrorLevel%
{
WinMinimize, Spark ahk_pid %ErrorLevel%
WinHide, Spark ahk_pid %ErrorLevel%
}
Return
which of course doesn't fire up the program but I thought I'd try to get the other part working first.

So I have the program running and verified spark.exe is definitely a process. But using this just makes an entry for Spark on the taskbar below but doesn't actually open a window, or open if I click on it. The system tray icon is still responsive and will respond to its right-clicked commands, but the one on the taskbar doesn't and when right-clicked and maximized it locked up the system until I killed the Spark process.

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
store errorlevel in another variable right after the process command, since some of the other commands you are using may write over errorlevel. Use your new variable in all the commands after.

Ron7
  • Members
  • 3 posts
  • Last active: Jun 25 2012 07:21 PM
  • Joined: 25 Jun 2012
Thanks for the tip. But I got the exact same behavior using this code:
#s::
DetectHiddenWindows, Off
Process, Exist, Spark.exe
SparkVar = %ErrorLevel%
IfWinNotExist Spark ahk_pid %SparkVar%
{
WinShow, Spark ahk_pid %SparkVar%
WinActivate, Spark ahk_pid %SparkVar%
}
Else
IfWinExist Spark ahk_pid %SparkVar%
{
WinMinimize, Spark ahk_pid %SparkVar%
WinHide, Spark ahk_pid %SparkVar%
}
Return


epconfig
  • Members
  • 30 posts
  • Last active: Feb 12 2015 12:17 AM
  • Joined: 10 Oct 2007
You can detect hidden windows (system tray) only if DetectHiddenWindows has been turned on. WinShow is the only exception.

Ron7
  • Members
  • 3 posts
  • Last active: Jun 25 2012 07:21 PM
  • Joined: 25 Jun 2012
Thanks. I actually got this code right from the thread nukchebi0 listed above, which seems like it is exactly what I want to do. But I went ahead and changed the first line to:
DetectHiddenWindows, On
and now what I see is the Spark program flashing on the taskbar below and then immediately disappearing. With this setting it is also a little strange in that after running the script and watching it flash and disappear, then if I go to the system tray icon and right click its Open option, it re-appears minimized on the taskbar. I can then click on the taskbar icon and it will open. But if I don't run the script it will act normally by opening up a window directly from the system tray as it should.