Jump to content
  • Announcements

    • Allan

      Forum Rules   04/13/2018

      Hello folks! As some things are being fixed, we'll keep you updated. Per hour the Forum Rules don't have a dedicated "Tab", so here is the place that we have our Rules back. New Users Lounge > [READ] - InsanelyMac Forum Rules - The InsanelyMac Staff Team. 
harmc0re

Need help with geektool scripting

9 posts in this topic

Recommended Posts

Hello,

 

Yesterday I installed GeekTool, which posts the output of .bash scripts to the desktop,

so you can put date, cpu usage, weather and other useful info on the desktop.

 

So, using google, my Java and my very basic C++ knowledge, I wrote two scripts so far, here's my current output:

 

2uyr9rn.jpg

 

Using this script for the bigger letters:

GeekTool_Time_Script.bash.txt

and this script for the smaller letters:

GeekTool_System_Stats_Script.bash.txt

 

I want to have additional info right on the desktop, but I need some help from you guys.

I will be searching further in the meantime, but will be more than happy if some people could help me solve some individual questions.

 

What I want to accomplish:

 

1) my name capitalized (I know it's easier to just put "Harm" there, but I want the script to be universal) Done, thanks ruger42!

2) remove the first zero and the space in 09:05 pm. Done, thanks ruger42!

3) I want the full date in English (so, not my native language), see lower Done, thanks ruger42!

4) the weather, without capital letters, see lower Done, thanks ruger42!

5) a counter for my emails, see lower Still looking for a Hotmail counter

6) other system info Still looking for a Battery meter

 

So this is what I would like to see on my display

 

Good evening Harm,

it's now 9:05pm.

Today's Saturday the 6th of August 2011.

 

It's 14 degrees outside and the weather is mostly cloudy.

You have 34 new emails, 34 in Hotmail and 0 in Gmail.

 

RAM: 20%

CPU: 8%

Battery: 100%

 

 

Ethernet: 192.168.0.2

 

External IP: 81.165.218.26

 

After that has been done, I will re-upload the script so everyone can use it. smile.gif

 

Update:

 

Here's a zip with my scripts. Note that they will need to be modified, and you'll need to

update bash in order to make them work properly.

Scripts.zip

Share this post


Link to post
Share on other sites

Here's some help with parts 1 - 3, but you'll need to update BASH to 4.2 for it to work properly (I followed the instructions here)

 

#!/bin/bash

 hour=`date +"%H"`
 day=`date +"%e" | sed -E 's/([^1]1)$/\1st/'| sed -E 's/([^1]2)$/\1nd/' |sed -E 's/([^1]3)$/\1rd/' | sed -E 's/([0-9])$/\1th/' | sed -e 's/^[ \t]*//'`
 dayw=`date +"%A"`
 monthyear=`date +"%B %Y"`

 time=`date +"%l:%M" | sed -e 's/^[ \t]*//'`
 am_pm=`date +"%p"`

 username=`LOGNAME`

 if [ $hour -ge 0 -a $hour -le 6 ]
 then
 echo "Good night ${username[@]^},"
 echo "		  it's now $time${am_pm,,}."
 fi

 if [ $hour -gt 6 -a $hour -le 12 ]
 then
 echo "Good morning ${username[@]^},"
 echo "		  it's now $time${am_pm,,}."
 fi

 if [ $hour -gt 12 -a $hour -le 16 ]
 then
 echo "Good afternoon ${username[@]^},"
 echo "		  it's now $time${am_pm,,}."
 fi

 if [ $hour -gt 16 -a $hour -le 23 ]
 then
 echo "Good evening ${username[@]^},"
 echo "		  it's now $time${am_pm,,}."
 fi

 echo "Today's $dayw the $day of $monthyear."

I'll try to come up with something for the weather a little later...

Share this post


Link to post
Share on other sites

Try this for the weather:

weather=`curl --silent "http://xml.weather.yahoo.com/forecastrss?p=FRXX4403&u=f" | grep -E '(Current Conditions:|F<BR)' | sed -e 's/Current Conditions://' -e 's/<br \/>//' -e 's/<b>//' -e 's/<\/b>//' -e 's/ F<BR \/>//' -e 's/<description>//' -e 's/<\/description>//'`

  weather2=`curl --silent "http://xml.weather.yahoo.com/forecastrss?p=FRXX4403&u=c" | grep -E '(Current Conditions:|C<BR)' | sed -e 's/Current Conditions://' -e 's/<br \/>//' -e 's/<b>//' -e 's/<\/b>//' -e 's/<BR \/>//' -e 's/<description>//' -e 's/<\/description>//'`

  conditions=`echo ${weather2,,}  | cut -f 1 -d ","`

  tempC=`echo ${weather2} | cut -f 2 -d "," | sed -e 's/^[ \t]*//' | cut -c1-2`

  if [ "$weather2" != "" ]
  then
  echo "It's $tempC degrees outside and the weather is $conditions."
  fi

All combined it should look like this:

post-497897-1312737419_thumb.jpg

 

 

This will get you the count of unread emails at Gmail (not my creation, found it on the web):

curl --silent https://username:password@mail.google.com/mail/feed/atom/ | awk '/<fullcount>/{print}' | grep -o "[0-9]\+"

I can't find any way to retrieve data from Hotmail...

Share this post


Link to post
Share on other sites

ruger42! Thanks for the fast and great help! :)

I sure didn't expect half of the things were going to be solved that fast! :o

 

I have some problems with the Gmail command you gave me,

I can't get it to work, it gives nothing back.

If I go to https://username:password@mail.google.com/mail/feed/atom/ in my browser, I see the RSS with 2 new emails, so I know I got the username and password right... :P

Share this post


Link to post
Share on other sites
ruger42! Thanks for the fast and great help! :)

I sure didn't expect half of the things were going to be solved that fast! :o

 

I have some problems with the Gmail command you gave me,

I can't get it to work, it gives nothing back.

If I go to https://username:password@mail.google.com/mail/feed/atom/ in my browser, I see the RSS with 2 new emails, so I know I got the username and password right... :P

Don't know what to tell you, the Gmail code works perfectly for me as a single command or as part of the shell script:

unreadCount=`curl --silent https://username:password@mail.google.com/mail/feed/atom/ | awk '/<fullcount>/{print}' | grep -o "[0-9]\+"`
  echo "You have $unreadCount unread emails at Gmail"

Now gives me this:

post-497897-1312751098_thumb.jpg

 

EDIT:

Make sure you're not using your full email address as the username, I seem to recall reading that if you use the @ symbol in the username field the script will not work...

Share this post


Link to post
Share on other sites

Here's some more stuff I found online for RAM, CPU, and Battery:

#!/bin/bash

##Change the value of totalRAM to match the amount of memory in your computer   

  myRAM=`top -l 1 -F -R | awk '/PhysMem/ {print "" $8+0}'`
  totalRAM=8192
  myPercentRAM=`expr $myRAM \* 100 / $totalRAM`

  echo "RAM: $myPercentRAM%"


  myCPU=`top -l 2 -F -R | awk '/CPU usage/ && NR>5 {printf "%d", $7+0}'`
  myCPU=`expr 100 - $myCPU`

  echo "CPU: $myCPU%"


  ioreg=`ioreg -w0 -l | grep "ExternalConnected|CurrentCapacity|MaxCapacity" | awk '{print $5}'`
  my_ac_adapt=`echo $ioreg | awk '{print $1}'`
  max_power=`echo $ioreg | awk '{print $2}'`
  cur_power=`echo $ioreg | awk '{print $3}'`
  bat_percent=`echo "scale=2;$cur_power / $max_power" | bc`
  bat_percent=`echo "$bat_percent * 100" | bc | sed 's/.00//'`

  if [ $my_ac_adapt == "Yes" ]
  then
  echo "Battery: $bat_percent% ↯"
  else
  echo "Battery: $bat_percent% ⚡"
  fi

I don't have a laptop so I can't verify if the battery percentage is actually working, but the rest seems to function properly...

Share this post


Link to post
Share on other sites

My Gmail counter is working properly now, like you said, I used my full email address. :(

 

The RAM and CPU are working good too,

 

Only the battery counter isn't.

 

The special thunderbolts are showing like this:

wl6feq.png

 

But I don't mind, I removed them. :D

But that still leaves me with no battery percentage.

 

Since you don't have a laptop, I will look myself to fix that.

 

Thank you so much for all the help! :)

Share this post


Link to post
Share on other sites
...But that still leaves me with no battery percentage.

 

Since you don't have a laptop, I will look myself to fix that.

 

Thank you so much for all the help! ;)

Glad to be of assistance, it was a fun learning experience...

 

Here's another script I found online that you can try for battery percentage:

ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%.2f%%", $10/$5 * 100)}'

Unfortunately I think you're out of luck with Hotmail - in order to get the number of unread emails you'd need to use IMAP, but Hotmail doesn't support that protocol, only POP3 which (from what I've read) doesn't provide the necessary functionality to retrieve such information. You can always forward your Hotmail messages to Gmail... :angel:

 

If you do manage to figure it out let us know!

Share this post


Link to post
Share on other sites
Glad to be of assistance, it was a fun learning experience...

 

Here's another script I found online that you can try for battery percentage:

ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%.2f%%", $10/$5 * 100)}'

Unfortunately I think you're out of luck with Hotmail - in order to get the number of unread emails you'd need to use IMAP, but Hotmail doesn't support that protocol, only POP3 which (from what I've read) doesn't provide the necessary functionality to retrieve such information. You can always forward your Hotmail messages to Gmail... :rolleyes:

 

If you do manage to figure it out let us know!

Okay, I found out that I had to change the output encoding setting in GeekTool to UTF8, allowing me to show the special symbols ↯ ⚡ and also the ° for degrees :D

 

mt2flf.jpg

 

And even better news: your battery meter works! :D

 

Sort of...

 

I had to switch the %10 and %5 because my battery percentage went from 100% to 101%, 102% when discharging :P

(Which would be cool if it was true :))

 

I also changed the "%.2f%%" to "%.0f" because I didn't want to show decimals, and I already added a % later in the script.

 

So this is my modified line of code:

ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("[color="#FF0000"]%.0f[/color]", [color="#FF0000"]$5/$10[/color] * 100)}'

 

Thanks x100!

 

Yeah, about Hotmail, I was also thinking that. ):

I have been looking for a script that could ask Mail.app if there are any new emails in Hotmail,

but I only found scripts that tell me the total number of new emails so far.

 

But I'll keep looking. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Posts

    • i think the "red light" you are referring to is that you have a optical SPDIF output (3.5 mm) combo jack. it most likely will be "red" when audio is active. 
    • Domanda , ma il tuo configplist lo ha settato cosi Gengik????
      Noto molte cose atipiche , tipo aperto con Clover configurator nella sezione ACPI il nome DSDT.aml NON è selezionato , quindi in teoria NON dovrebbe caricare il DSDT che hai in Clover ACPI Patch , se usi SSDT x la CPU NON dovrebbero servirti quelle personalizzazioni sempre in configplist sezione CPU ...
      Secondo me dovresti partire da un configplist pulito , xche sempre secondo me c'è rimasto delle schifezze di qualche tool x installare facile    EDIT
      Scaricando il configplist di jolly NOTO ha impostato +o- come intendevo fare io , sistemando quello  sopra elencato e bammmmm NON avvia , mi forniresti x favore Hack info che trovi nella mia firma ???
      Grazie
    •   Can you share the Clover folder that lets you boot?
    • yes it is. i can boot using a backup from a backup of my clover. i am just trying to fix the VGA /HDMI so i tried using the clover i got from Allan
    •     I mean't to fix that. The new attached EFI only contains new USB patch that will unlikely fix anything unless your hackintosh is installed on a USB drive. If it is installed on your hard drive, as I said, try playing with the patches I attached in the screenshot (i.e. disabling some of them).   Your SATA Mode is AHCI in the BIOS right?


×