From a script (e.g. REXX or BAT) how can I tell if Firefox is up and running?
System: Windows 7 Ultimate x64
I'm trying to open Firefox with multiple tabs open at one time using a program, which reads a configuration file (XML). I discovered when using the "-new-tab" command line parameter, I get one windows for each URL instead of one window with multiple tabs.
I can get it to work IF Firefox is already up and fully running. In other words its frames exist and are visible. If Firefox is only running (say in the tasklist) but not yet visible, the user again gets one window for each URL (e.g. 5 URLs = 5 Firefox windows) instead of 1 window with 5 tabs.
Thus I've been wondering is there a method in Windows or using Firefox to tell from a script (e.g. REXX, BAT, Perl, etc) if Firefox is completely visible and running, so when you a script uses the "-new-tab" parameter the tab appears instead of a window (per URL).
Τροποποιήθηκε στις
Όλες οι απαντήσεις (3)
You can either send
- Several firefox.exe -new-tab http://en.wikipedia.org commands.
- Or you can send a single firefox.exe -new-tab http://en.wikipedia.org -new-tab http://wiki.mozilla.org -new-tab http://blog.mozilla.org command.
Either way, the end result is the same: Firefox starts if it wasn't already running, and the links open each in a separate tab.
From your description, it sounds like you're doing the following instead.
- Sending a single firefox.exe -new-tab http://en.wikipedia.org http://wiki.mozilla.org http://blog.mozilla.org command.
This causes Firefox to start if it wasn't already running, open a new tab with Wikipedia in it in the main window, then open a new window with the remaining links, each in their own tab.
To use a batch file to check if Firefox is running,
tasklist /fi "IMAGENAME eq firefox.exe" 2>NUL | find /i /n "firefox.exe">NUL / if %ERRORLEVEL%==1 goto nofirefox
Where the :nofirefox section of your batch file performs whatever actions you want in that case.
Hello and thank you for your reply,
Now I wish I hadn't "cleaned" up my question to make it easier to read, but instead included examples. In my case, the initial firefox.exe command I used was:
cmd /C start "FFXI Firefox" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -new-tab "http://wiki.ffxiclopedia.org/wiki/Main_Page" -new-tab "http://wiki.ffxiclopedia.org/wiki/Category:Combat_Skills" -new-tab "file:///C:/Users/Bertram Moshier/Programs/FFXI/FFXI_Skill_Caps.html" -new-tab "http://wiki.ffxiclopedia.org/wiki/Skill_Ups:_A_Guide_by_Kyrial" -new-tab "http://www.mithrapride.org/vana_time/" -new-tab "http://wiki.ffxiclopedia.org/wiki/Dragoon" "http://ffxi.somepage.com/mobdb/" -new-tab "http://www.ffxiah.com/item/4558/yagudo-drink" -new-tab "http://greatbigsea.guildlaunch.com/forums/index.php?gid=108403" -new-tab "http://guildwork.com/games/ffxi/shouts"
As you can see in this version I put "-new-tab" in front of each URL and the result, since firefox version 9.0.1 has been:
1) If firefox.exe is fully up and running a tab for each URL opens in one window. 2) If firefox.exe is not fully up and running a window for each URL opens with only one tab.
So, ah, I have been trying the -new-tab method from the start. Recently, I tried removing the -new-tab and it has been working, but I think that is more of a fluke than correctly working, as it goes against the documentation.
As for tell if firefox is up and running, thanks! I've been using the following code, which is similar to yours. What I found, though, is simply having firefox.exe up and running in advance (or starting it) is NOT enough. Like your code, mine, tells if it is running in the Window's tasklist. Yet, my experience, thus far, has been until the firefox window appears, you still get the multiple windows for each "-new-tab" you send. Only if firefox.exe is already FULLY up and running with its windows visible does the "-new-tab" work per the documentation.
Here is the core code I've been using (using REXX) -- this is static code on the URL and not the XML configuration version.
NOTE: I think it is basically the same as your code, but longer . . . . My hope was the code would wait till firefox would be up enough for the "-new-tab" to work, which I find to be between 8 and 15 seconds depending upon the system. Again what I discovered is simply having the tasklist command show firefox.exe running is NOT enough. Well, this is true on my Windows 7 x64 system (Firefox 9.0.1 - 16)
firefox_found = 0
FFXI_Website_Queue = 'FFXI_Website' rc = rxqueue('delete',FFXI_Website_Queue) rc = rxqueue('create',FFXI_Website_Queue) rc = rxqueue('set',FFXI_Website_Queue)
rc = !!Firefox_Exists() if rc = 0 then do
'cmd /C start /D "C:\Program Files (x86)\Mozilla Firefox\" "FFXI Firefox" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"' rc = 0 do until rc = 1 rc = !!Firefox_Exists() call SysSleep(1) end end
'cmd /C start "FFXI Firefox" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -new-tab "http://wiki.ffxiclopedia.org/wiki/Main_Page" -new-tab "http://wiki.ffxiclopedia.org/wiki/Category:Combat_Skills" -new-tab "file:///C:/Users/Bertram Moshier/Programs/FFXI/FFXI_Skill_Caps.html" -new-tab "http://wiki.ffxiclopedia.org/wiki/Skill_Ups:_A_Guide_by_Kyrial" -new-tab "http://www.mithrapride.org/vana_time/" -new-tab "http://wiki.ffxiclopedia.org/wiki/Dragoon" -new-tab "http://ffxi.somepage.com/mobdb/" -new-tab "http://www.ffxiah.com/item/4558/yagudo-drink" -new-tab "http://greatbigsea.guildlaunch.com/forums/index.php?gid=108403" -new-tab "http://guildwork.com/games/ffxi/shouts"'
rc = rxqueue('delete',FFXI_Website_Queue) call !!EOJ 0
/* >>>>>>>>>>>>>>>>>>>> Insert your subroutines here <<<<<<<<<<<<<<<<<<<< */
/*------------------------------------------------------------------------*\ | | | Subroutine section | | | \*------------------------------------------------------------------------*/ !!Firefox_Exists: 'tasklist /V /FI "IMAGENAME eq firefox.exe" | RxQueue' FFXI_Website_Queue '/FIFO'
do while queued() <> 0
parse pull Image_Name PID Session_Name Session_Number Memory_Usage Status User_Name CPU_Time Window_Title if Image_Name = 'firefox.exe' then do firefox_found = 1 leave end end
return firefox_found
Bertram_Moshier wrote:
Only if firefox.exe is already FULLY up and running with its windows visible [...]
I'm pretty sure a simple batch file can't check if the Firefox window is visible, only if the process is running. If you're launching Firefox via the batch file as well, you can add a 15-second delay with timeout /t 15 /nobreak
Bertram_Moshier wrote:
cmd /C start
That's why you get separate windows. When launching firefox.exe directly, it behaves normally. The /b parameter of the start command doesn't help, so I have no suggestions for making your particular method work.
If you detail your exact requirements, we may be able to suggest a different way to do what you want. As it is, I don't see what you have to gain from this convoluted command line method.
If the point is just to open several sites in separate tabs, you can bookmark all the sites into a single folder, then place that folder on the Bookmarks Toolbar. It would then take you 1 left-click on the Firefox icon to launch it, and 1 middle-click on the folder on the Bookmarks Toolbar to open all those bookmarks in separate tabs.