-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
> Time to start hacking.
>
> BTW the DynamicPopupAction stuff is straight out of the man page (fvwm
> 2.5.10)
Sounds like the mechanism to use. I think I have a working
implementation:
Two scripts: tally.rb (the execution wrapper) and menu.rb (converts the
usage database into a menu). It sorts them by usage frequency (average
uses per day with second's accuracy) and supports a maximum number of
entries. menu.rb should be used with DynamicPopupAction...
Example:
<snip>
[EMAIL PROTECTED] rb]$ ./tally.rb xcdroast
[EMAIL PROTECTED] rb]$ ./tally.rb xmms
[EMAIL PROTECTED] rb]$ ./tally.rb xcdroast
[EMAIL PROTECTED] rb]$ ./tally.rb xclock
[EMAIL PROTECTED] rb]$ cat ~/.tally_db
xclock 1 1083791904
xcdroast 2 1083791870
xmms 1 1083791877
[EMAIL PROTECTED] rb]$ ./menu.rb
AddToMenu FrequentMenu "Common Applications" Title
+ "xclock" Exec exec tally.rb xclock # frequency 124.48988376584 uses/day
+ "xcdroast" Exec exec tally.rb xcdroast # frequency 63.2025731382508 uses/day
+ "xmms" Exec exec tally.rb xmms # frequency 37.3364468851539 uses/day
</snip>
(The averages are very large because we're dividing by about 30 seconds or
so).
The point is, fvwm is great because it's not only configurable by you and
I, but also by scripts or whatever. I don't think one could do this kind
of thing with gnome or kde.
Enjoy,
- --
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Nicholas Paul Johnson
o nickjohnson \at\ virginia \dot\ edu
o 3ebf10a7 subkeys.pgp.net
o http://manjac.ath.cx/nick
o "When all you've got is a hammer,
everything looks like a nail.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Made with pgp4pine 1.75-6
iD8DBQFAmVySfnGNDj6/EKcRAjLqAJ47/MwAYsarmiw/d4ULZrCxbKbVqQCeLU/s
afs8Qp251Vb4maxVVQbcxl0=
=6TR0
-----END PGP SIGNATURE-----
#!/usr/local/bin/ruby -w
# files... don't need to change
dbFile = "#{ENV['HOME']}/.tally_db"
# fvwm-name for the menu
menuName = 'FrequentMenu'
# max entries in this menu
maxEntries = 10
# load db
db = Hash.new
begin
IO.readlines(dbFile).each do |line|
prog, count, firstTime = line.split
db[prog] = [count.to_i, firstTime.to_i]
end
rescue
end
# save an FVWM menu
puts "AddToMenu #{menuName} \"Common Applications\" Title"
# sort entries in decending order by usage frequency
sorted = db.sort do |a,b|
numa = a[1][0].to_f
dura = Time.now.to_f - a[1][1].to_f
numb = b[1][0].to_f
durb = Time.now.to_f - b[1][1].to_f
numb / durb <=> numa / dura
end
# write each program as a menu entry
entryCount = 0
sorted.each do |entry|
if entryCount < maxEntries
name = entry[0]
uses = entry[1][0].to_f
dur = (Time.now.to_f - entry[1][1]) / ( 60.0 * 24.0 )
freq = uses / dur
puts "+ \"#{name}\" Exec exec tally.rb #{name} # frequency #{freq}
uses/day"
entryCount += 1
end
end
#!/usr/local/bin/ruby -w
# files... don't need to change
dbFile = "#{ENV['HOME']}/.tally_db"
# determine name of command being executed
commandName = ARGV[0]
# update the program usage database
# load db and increment/insert the program we are running
db = { commandName => [1, Time.now.to_i] }
begin
IO.readlines(dbFile).each do |line|
prog, count, firstTime = line.split
count = count.to_i
count += 1 if prog == commandName
db[prog] = [count, firstTime.to_i]
end
rescue
end
begin
# save the database
File.open(dbFile, 'w') do |fout|
db.each_pair do |key,val|
fout.syswrite "#{key} #{val[0]} #{val[1]}\n"
end
end
rescue
puts "Cannot open for writing"
end
# execute the program as normal
exec ARGV.join(' ')