Page 1 of 2
Kill FireFox
Posted: Saturday 14th September 2019 8:41pm
by cage
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.
Public Sub Form_Open()
CheckFox
End
Public Sub BuExit_Click()
Me.Close
End
Public Sub BuKillFox_Click()
Shell "pkill 'firefox'"
Wait 0.5
BuKillFox.Enabled = False
CheckFox
End
Public Sub CheckFox()
Dim sState As String
sState = Null
Shell "pgrep -x 'firefox'" To sState
Wait 0.5
If sState = Null Then
Label1.text = "FireFox Not Running"
Else
Label1.Text = "FireFox Is Running"
BuKillFox.Enabled = True
Endif
End
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.
Re: Kill FireFox
Posted: Sunday 15th September 2019 12:44am
by Technopeasant
I mean, sure, you could just use the task manager to do this... but why not do it in Gambas?
Re: Kill FireFox
Posted: Sunday 15th September 2019 8:08am
by cage
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.
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.
Re: Kill FireFox
Posted: Monday 16th September 2019 9:18am
by vuott
cage wrote: ↑Saturday 14th September 2019 8:41pmFeel free to modify the program to your tastes.
...without using Shell:
Private wid As Integer[]
Public Sub Form_Open()
CheckFox
End
Public Sub BuKillFox_Click()
Dim dw As DesktopWindow
dw = Desktop.Windows.FromHandle(wid[0])
dw.Close()
Wait 1
BuKillFox.Enabled = False
CheckFox
End
Public Sub CheckFox()
wid = Desktop.FindWindow("*Firefox*", Null, Null)
If wid.Count == 0 Then
Label1.text = "FireFox Not Running"
Else
Label1.Text = "FireFox Is Running"
BuKillFox.Enabled = True
Endif
End
Re: Kill FireFox
Posted: Tuesday 17th September 2019 3:44am
by cage
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?
Re: Kill FireFox
Posted: Tuesday 17th September 2019 6:43am
by vuott
cage wrote: ↑Tuesday 17th September 2019 3:44am
... but I get an error when I run it.
Where ?
Re: Kill FireFox
Posted: Tuesday 17th September 2019 8:00am
by cage
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.
Re: Kill FireFox
Posted: Tuesday 17th September 2019 8:15am
by vuott
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.
Re: Kill FireFox
Posted: Tuesday 17th September 2019 7:13pm
by cage
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.
Re: Kill FireFox
Posted: Thursday 19th September 2019 3:33am
by Technopeasant
cage wrote: ↑Sunday 15th September 2019 8:08am
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.
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."