Kill FireFox

Post

Posted
Rating:
#1 (In Topic #313)
Avatar
Regular
cage is in the usergroup ‘Regular’
For some reason after the latest update to FireFox it seems that the browser does not close every time.  Thanks to cogier's caps lock example I figured out how to check to see if FireFox is running or not, and to kill it if it is.  The program is very simple, if FF is running the program will tell you it is, then the kill button will be enabled.  Then just click the Kill FireFox button and the program is shut down completely.

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3. CheckFox
  4.  
  5.  
  6. Public Sub BuExit_Click()
  7.  
  8.  
  9.  
  10. Public Sub BuKillFox_Click()
  11.  
  12.   Shell "pkill 'firefox'"
  13.   Wait 0.5
  14.   BuKillFox.Enabled = False
  15.   CheckFox
  16.  
  17. Public Sub CheckFox()
  18.  
  19.   Dim sState As String
  20.   sState = Null
  21.  
  22. Shell "pgrep -x 'firefox'" To sState
  23. Wait 0.5
  24. If sState = Null Then
  25.   Label1.text = "FireFox Not Running"
  26.   Label1.Text = "FireFox Is Running"
  27.   BuKillFox.Enabled = True
  28.  

You will nee to create a Label and two buttons. I used BuExit, BuKillFox names for
the buttons and Label1 for the text box.  Feel free to modify the program to your tastes.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
Technopeasant is in the usergroup ‘Regular’
I mean, sure, you could just use the task manager to do this… but why not do it in Gambas?  :lol:
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Regular
cage is in the usergroup ‘Regular’
I look at it this way.  If you have $2000.00 worth of tools why use a breaker bar to break loose the lug nuts on you car when you can use a impact wrench.   I have done it with the task manager, and a script from the command line. But it's more fun making things work with Gambas. :D  Gambas is just another tool to make computing life much easier.  I use to program with VB1-6, and while it was good tool  Gambas is much better tool at doing things.
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
vuott is in the usergroup ‘Regular’

cage said

Feel free to modify the program to your tastes.
…without using Shell:

Code (gambas)

  1.  
  2.  
  3. Public Sub Form_Open()
  4.  
  5. CheckFox
  6.  
  7.  
  8.  
  9. Public Sub BuKillFox_Click()
  10.  
  11.   Dim dw As DesktopWindow
  12.  
  13.   dw = Desktop.Windows.FromHandle(wid[0])
  14.  
  15.   dw.Close()
  16.   Wait 1
  17.   BuKillFox.Enabled = False
  18.   CheckFox
  19.  
  20.  
  21. Public Sub CheckFox()
  22.  
  23.   wid = Desktop.FindWindow("*Firefox*", Null, Null)
  24.  
  25.   If wid.Count == 0 Then
  26.     Label1.text = "FireFox Not Running"
  27.   Else
  28.     Label1.Text = "FireFox Is Running"
  29.     BuKillFox.Enabled = True
  30.    

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Regular
cage is in the usergroup ‘Regular’
 That looks very interesting but I get an error when I run it.  Can you tell me how and I need to make it work?
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
vuott is in the usergroup ‘Regular’

cage said

… but I get an error when I run it.

Where ?

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Regular
cage is in the usergroup ‘Regular’
 Okay got it working but now it always shows Fire Fox as not running.  In other words wid.Count always equals zero.  Not sure what desktop or Distro your are using but I am using Arch Linux with a XFCE desktop.  I never used the gb.desktop before and would really like to learn and understand it.  It looks like an interesting way to do things.
Online now: No Back to the top

Post

Posted
Rating:
#8
Regular
vuott is in the usergroup ‘Regular’
I use Linux Mint 19.2 Tina - Desktop: Cinnamon 4.2.4

However you can also try using the other two parameters of the Desktop.FindWindow() function.

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#9
Avatar
Regular
cage is in the usergroup ‘Regular’
 Thanks vuott for the information.  It's weird but I tried it again today and for some reason it works fine.  Really strange.  Anyone that uses this way of vuott needs to know that you have to install gb.desktop and gb.image to make it work.  I found that when installing those components to save the project and reload it. I think that was my problem as to why it wasn't working correctly.  After reloading the project it worked fine.
Online now: No Back to the top

Post

Posted
Rating:
#10
Avatar
Regular
Technopeasant is in the usergroup ‘Regular’

cage said

I look at it this way.  If you have $2000.00 worth of tools why use a breaker bar to break loose the lug nuts on you car when you can use a impact wrench.   I have done it with the task manager, and a script from the command line. But it's more fun making things work with Gambas. :D  Gambas is just another tool to make computing life much easier.  I use to program with VB1-6, and while it was good tool  Gambas is much better tool at doing things.

For me, it is often more fun to use the less than ideal tool to get the job done, just to show that it can be done.

"I am endeavoring, ma'am, to construct a mnemonic memory circuit using stone knives and bearskins."

 :ugeek:
Online now: No Back to the top

Post

Posted
Rating:
#11
Avatar
Regular
cage is in the usergroup ‘Regular’
"I am endeavoring, ma'am, to construct a mnemonic memory circuit using stone knives and bearskins."

So how is your mnemonic memory circuit project coming along?
Online now: No Back to the top
1 guest and 0 members have just viewed this.