LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-09-2011, 01:48 PM   #1
SweetLou
Member
 
Registered: Oct 2004
Distribution: Debian Testing
Posts: 171

Rep: Reputation: 30
Run a Command After Closing Firefox


I am creating a couple of scripts that will take Firefox's Bookmarks and place them in XFCE's menu. I've pretty much figured that part out, just a couple of tweaks need to be done.

What I want to happen is when Firefox closes that my scripts will run. Or I just thought of this, maybe if Firefox's bookmarks has been changed. But, I have no idea on how to do this.

Could a bash or Python script be used to open Firefox and somehow wait until Firefox closes to run the bookmark updater script? Or even better, only run when Firefox's sqlite bookmarks' table has changed.

Any other ideas?
 
Old 12-09-2011, 03:27 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
The easiest way is the following:
Code:
#!/bin/bash
firefox && command
"command" will execute after the firefox process finishes normally. Note that if firefox crashes, or an error is generated, "command" will not run, due to using &&.

Cheers,

Josh
 
1 members found this post helpful.
Old 12-09-2011, 03:30 PM   #3
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 172

Rep: Reputation: 56
It looks like the places.sqlite file is what stores the bookmarks, so you could conceivably write a bash script with a while loop that checks (at a specified interval, say once every 10 minutes) whether the file was updated during the last interval, and if so, run your menu script.

Code:
while [ TRUE ]

do
	if [ -n "$(find /home/user/.mozilla/firefox/XXXXXXX.default/places.sqlite -mmin -10)" ]
	then
	          run your script here
	fi
sleep 10m
done
 
Old 12-09-2011, 03:33 PM   #4
SweetLou
Member
 
Registered: Oct 2004
Distribution: Debian Testing
Posts: 171

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by corp769 View Post
The easiest way is the following:
Code:
#!/bin/bash
firefox && command
"command" will execute after the firefox process finishes normally. Note that if firefox crashes, or an error is generated, "command" will not run, due to using &&.

Cheers,

Josh
Thanks, I didn't know about that technique. That should work. I just need to make a bash script that will run the two python files I have made.
 
Old 12-09-2011, 03:40 PM   #5
SweetLou
Member
 
Registered: Oct 2004
Distribution: Debian Testing
Posts: 171

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by thesnow View Post
It looks like the places.sqlite file is what stores the bookmarks, so you could conceivably write a bash script with a while loop that checks (at a specified interval, say once every 10 minutes) whether the file was updated during the last interval, and if so, run your menu script.

Code:
while [ TRUE ]

do
	if [ -n "$(find /home/user/.mozilla/firefox/XXXXXXX.default/places.sqlite -mmin -10)" ]
	then
	          run your script here
	fi
sleep 10m
done
Sounds good, but places.sqlite also stores the history, typed addresses among other things, so every time you open Firefox or go to a new site/page the database will be updated. The table 'moz_bookmarks' is the table with just bookmark information. Not even all of it, there is another table with the name of the bookmark. I would need to just check if the table 'moz_bookmarks' was altered, unless I wanted to run my scripts every x minutes.

I was going to do a cronjob once a day to update XFCE's menu. I think I would rather use a cronjob than to run automatically every x minutes that Firefox is open.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is Firefox closing unexpectedly? LaurenceC Linux - Newbie 1 05-16-2009 08:56 PM
Firefox 2.0.0.2 on Ubuntu closing unexpectedly. Tear Syden Linux - Software 2 03-01-2007 12:41 PM
Firefox closing unexpectedly jmtjet Ubuntu 7 09-19-2006 11:07 PM
Javascript:closing Firefox command albatros_la Programming 5 08-24-2006 08:21 AM
firefox instances closing bong.mau Linux - Software 1 06-09-2006 05:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration