Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Check if process is running


  • Please log in to reply
2 replies to this topic
foxtrot123
  • Members
  • 4 posts
  • Last active: Jul 30 2009 05:09 PM
  • Joined: 28 Jul 2009
I'm new to AHK and am trying to write a simple script to check if Firefox is running. If Yes, then open a new tab (Send^T). If not, start Firefox. My current script opens a new instance of Firefox regardless of whether it's already running.

This is what I have:

^F::

If Process, Exist, firefox
{
    WinActivate         ; is this line even necessary?
    Send^T               ; firefox shortcut for new tab
}
else
{
    Run Firefox
    WinWait Google - Mozilla Firefox  ; this is the title of my homepage
}
; some more commands will go here once the above is finished
return
Suggestions?

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Try this instead

SetTitleMatchMode, 2
Process, Exist, firefox.exe
if !ErrorLevel = 0
{
    IfWinNotActive, Mozilla Firefox,
    WinActivate, Mozilla Firefox, 
    WinWaitActive, Mozilla Firefox, 
    Send, ^t
}
else
{
    Run Firefox
    WinWait, Mozilla Firefox,
}
; some more commands will go here once the above is finished
return

You may have to add a sleep before the send.

Posted Image

don't duplicate, iterate!


Matas
  • Members
  • 49 posts
  • Last active: Mar 12 2010 07:29 PM
  • Joined: 07 Mar 2009
Here you are: (tested works great), uhhh, someone have ansswered already :D

SetTitleMatchMode, 2

^F::
IfWinExist, Mozilla
{
    WinActivate
    Send, ^t               ; firefox shortcut for new tab
}
else
    Run, %A_ProgramFiles%\Mozilla Firefox\firefox.exe
return