Topic: https://brettterpstra.com/2011/09/16/geeklet-top-cpu-processes/
hide preview

What's next? verify your email address for reply notifications!

Nils Fischer 13y, 138d ago

Hi,
can´t run these Geeklets on my computer. I´ve downloaded GeekTool from the MacAppStore, btw.
I did everything like you said, but if I write down the path in GeekTool or NerdTool, nothing happens. I think, I´m doing something wrong with this ruby-thing. The command is: "ruby /Users/Nils/Documents/Geektool/Process/cpumeter.rb"
I hope someone here can help me?
Nils
PS: Sorry for my english, I´m only 14 and german.

remark link
hide preview

What's next? verify your email address for reply notifications!

Brett 13y, 138d ago

Try running that command in Terminal and see what you get. It's possible you need to specify a complete path to Ruby… i.e. /usr/bin/ruby

remark link parent
hide preview

What's next? verify your email address for reply notifications!

Nils Fischer 13y, 138d ago

localhost:~ Nils$ /usr/bin/ruby /Users/Nils/Documents/Geektool/Process/cpumeter.rb
Top CPU processes

localhost:~ Nils$
That´s what I get when I run the file from Terminal. For me, it looks like it is running correctly. But GeekTool can´t run I anyways?
Thanks for your help!
Nils

remark link parent
hide preview

What's next? verify your email address for reply notifications!

Brett 13y, 138d ago

Is GeekTool able to process other scripts for you? Do you have any others running on the Desktop that have a similar command?

remark link parent

load more (6 remarks)
hide preview

What's next? verify your email address for reply notifications!

Brett 13y, 138d ago

Is there any chance your ps output in Terminal uses commas as a separator instead of decimal points? I'm thinking that the script might be hanging up on the regular expression /^(.*?)\s+(\d{1,3}\.\d)$/.

Contact me through the form and send me the output of the ps command you just ran, I'll help you debug from there.

hide preview

What's next? verify your email address for reply notifications!

Nils Fischer 13y, 138d ago

ps -arcwwwxo "command %cpu"Works perfect. There are displayed some processes. Perhaps, I copied something wrong?
Nils

hide preview

What's next? verify your email address for reply notifications!

Brett 13y, 138d ago

Is your paste above correct? Because it looks like it's not showing the processes in Terminal, either, which means something in the script isn't working for you.

Try running ps -arcwwwxo "command %cpu" in Terminal and see what you get.

hide preview

What's next? verify your email address for reply notifications!

Nils Fischer 13y, 138d ago

It displays "Top CPU Processes", now. Progress! The Terminal says nothing new. http://cl.ly/BXOQ
Do you have any Ideas?
Nils

hide preview

What's next? verify your email address for reply notifications!

Brett 13y, 138d ago

Try doing a chmod a+x /path/to/cpumeter.rb and then set the geeklet up without the /usr/bin/ruby part. So the command would just be /path/to/cpumeter.rb. See if that helps at all.

hide preview

What's next? verify your email address for reply notifications!

Nils Fischer 13y, 138d ago

Yes, I can run 2 pieces of the weather geeklet (http://brettterpstra.com/ge... example. But the current-thing doesn´t work, too.
Nils

hide preview

What's next? verify your email address for reply notifications!

Michael Dingler 13y, 186d ago

Neat script, but your spacer function has a small off-by-one error, i.e. truncated output has a shorter column length.

Also, for some kind of reason, if I invoke ps with -o "command %cpu", I get a truncated command line, which doesn't happen if I do a `-o "%cpu command".

So in my version I simply changed the regex, and then swapped $1 and $2 around in the body. Also, I used this spacer function, to make it easier if I ever wanted a wider version:

def spacer(str, max=16)
(str.length > max-1 ? "%-.#{max-2}s… " : "%-#{max}.#{max}s") % str
end
remark link
hide preview

What's next? verify your email address for reply notifications!

Tim Lahey 13y, 169d ago

Thanks. That was kind of bugging me, but I did need metafour's fix to get the ellipses without the space. Using Brett's original script I was having spacing problems with the truncated lines so the alignment would get messed up.

That said, I'm really enjoying Brett's series on these additions. I had been just using GeekTool (now I'm using NerdTool) mainly to display keyboard shortcuts (and Dr. Drang's SuperDuper! log / Dropbox conflcts). Now, I'm trying to think of other things I might want on the desktop.

hide preview

What's next? verify your email address for reply notifications!

metafour 13y, 184d ago

Your script seems to add a space between the end of the process name string and the ellipsis. I modified it so that the ellipsis is directly attached to the process name. Not sure if it's the best way to do it since I don't really know ruby.

(str.length > max-1 ? "%-.#{max - 3}s…  " : "%-#{max}.#{max}s") % str
hide preview

What's next? verify your email address for reply notifications!

Brett 13y, 186d ago

Thanks! Mine works perfectly for me as is, but your tips will likely help a lot people for whom it doesn't :).

hide preview

What's next? verify your email address for reply notifications!