Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Status
Not open for further replies.
Hi,

I have a script that returns how much of my monthly peak is used but I cannot get it to return in gigabytes instead of bytes.

Code:
-

content


Would anyone know what to add in order for it to return the numbers under Peak and Offpeak in gigabytes (1GB = 1 000 000 000) and for it to be to the nearest two decimals? (Eg: "Peak: 11.20GB / 100GB used")
 
Last edited:
This post is ages old - hopefully the question can be answered.

Where did you get those icons from? Is it just a psd that you created? (If so, can you send me it? along with the font/font name that you used)

If this hasn't already been answered, PM me your email address and I'll send you the file over.

*goes looking for the file*
 
how did you get the pm in lowercase??

I have looked all over the place and everywhere it says
date +%P

the capital P for lowercase am/pm but when I do it, it only shows a capital P no lowercase

While I don't know why +%P isn't working, you could always use translate to turn the characters into lowercase after the fact...

Code:
date "+%p" | tr [A-Z] [a-z]
 
I've been using GeekTool for quite some time now and found help in setting stuff up ages ago and determined that I needed to return the favor with my stock ticker script.

It reads from a flat text file the market and ticker symbol and then lays it all out in a table (therefore you need a monospace font for this, sorry).

Bash script: I called it tickerv2.sh
Code:
#!/bin/bash
# Stock Data Grabber - Version 2
# Robert Wolterman - 2010
# Pulls data from a list of stocks for easier use in geektool
# Original web page parsing found on macrumers.com forum

# OUTPTYPE OF -c IS FOR COLORED OUTPUT
# OUTPTYPE OF -n IS FOR NONCOLORED OUTPUT
OUTPTYPE=$1

# SETS UP THE VARIABLE FOR THE TICKER FILE
TICKFILE=$2

# Check for ethernet connection
ping -c 1 www.google.com >/dev/null 2>&1
ret="$?"

# if i have an inet connection
if [ "$ret" = "0" ]; then

    # clear out old stockfile when script updates
    rm /tmp/geektool/stocklist

    # GET DATA FROM THE FILE
    cat $TICKFILE | while read line
    do 
        tmp="${line:0:1}"
        if [ $tmp != "#" ]; then
	        MARKET=`echo "${line}" | cut -d " " -f1`
	        SYMBOL=`echo "${line}" | cut -d " " -f2`
	
		    # FOR THE ACTUAL NASDAQ, DOW JONES, OR S&P 500 INDEX
			if [ "$MARKET" = "INDEXNASDAQ:.IXIC" ] || [ "$MARKET" = "INDEXDJX:.DJI" ] || [ "$MARKET" = "INDEXSP:.INX" ]; then
		        URL=http://www.google.com/finance?q=$MARKET
			# GENERAL STOCKS
			elif [ "$MARKET" = "NYSE" ] || [ "$MARKET" = "NASDAQ" ] || [ "$MARKET" = "AMEX" ] || [ "$MARKET" = "EPA" ] || [ "$MARKET" = "AMEX" ] || [ "$MARKET" = "TSE" ] || [ "$MARKET" = "LON" ] || [ "$MARKET" = "ETR" ] || [ "$MARKET" = "OTC" ]; then
		        URL=http://www.google.com/finance?q=$MARKET:$SYMBOL
			else
			    echo "No input given"
			fi
			
			# DOWNLOAD FILE TO /TMP
			curl --silent $URL > /tmp/geektool/$SYMBOL.stock
		
		    # COMPANY ID
		    COMPID=`grep 'var _companyId =' /tmp/geektool/$SYMBOL.stock | cut -d '=' -f2 | cut -d ';' -f1 | cut -d " " -f2`
		    # VALUE
		    STKVAL=`grep "ref_$COMPID\_l" /tmp/geektool/$SYMBOL.stock | cut -d ">" -f2 | cut -d "<" -f1`
		    # VALUE OF CHANGE IN DOLLARS
		    CHANGEVAL=`grep "id=\"ref_$COMPID\_c" /tmp/geektool/$SYMBOL.stock | cut -d ">" -f3 | cut -d "<" -f1`
		    # GET THE PLUS/MINUS OF THE CHANGE
		    PNE=${CHANGEVAL:0:1}
		    # VALUE OF CHANGE IN PERCENT
		    CHANGEPER=`grep "id=\"ref_$COMPID\_cp" /tmp/geektool/$SYMBOL.stock | cut -d ">" -f2 | cut -d "<" -f1`
		    # FIGURE OUT COLOR FOR POS/NEG CHANGE AND ECHO TO THE TMP FILE
		    if [ $PNE == "-" ]; then
		        # NEGATIVE CHANGE
		        BCOL="-"
		    elif [ $PNE == "+" ]; then
		        # POSITIVE CHANGE
		        BCOL="+"
		    else
		        # NO CHANGE
		        BCOL="="
		    fi

		    # DEPENDING ON OUTPTYPE, PERFORM THE PROPER ACTION
            if [ $OUTPTYPE == "-n" ]; then
                # DUMP DATA INTO THE TEMP FILE TO ENABLE TABLE CREATION
                echo $SYMBOL: $STKVAL $CHANGEVAL $CHANGEPER >> /tmp/geektool/stocklist
            elif [ $OUTPTYPE == "-c" ]; then
                # DUMP DATA INTO THE TEMP FILE FOR COLOR TABLE CREATION
                echo $BCOL";"$SYMBOL";"$STKVAL";"$CHANGEVAL";"$CHANGEPER >> /tmp/geektool/stocklist
            fi
        fi
    done

    if [ $OUTPTYPE == "-n" ]; then
        # OUTPUT TO A TABLE
        (printf "%s\t%s\t%s\t%s\n"; cat /tmp/geektool/stocklist) | column -t
    elif [ $OUTPTYPE == "-c" ]; then
	    # OUTPUT COLORS
	    awk 'BEGIN{
	        FS=";";
	        }{ 
	    	if ($1 == "+")
	    	    printf "\033[42;1;37m%-10s%-12s%-8s%-8s\n",$2,$3,$4,$5;
	    	else if ($1 == "-")
	     	    printf "\033[41;1;37m%-10s%-12s%-8s%-8s\n",$2,$3,$4,$5;
	    	else
	     	    printf "%-10s%-12s%-8s%-8s\n",$2,$3,$4,$5;
	    }' /tmp/geektool/stocklist
    fi
    
else
    echo "No internet connection"
fi

Flat text file format: I called this tickerlist.txt (NASDAQ and DOW have to have the markets that way, couldn't work it without that)
Code:
INDEXNASDAQ:.IXIC NASDAQ
INDEXDJX:.DJI DOW
NYSE UA
NYSE EK
NYSE SHS
NYSE BA
NYSE LMT
NYSE S
NYSE PEP
NASDAQ GOOG
NASDAQ AAPL

The flat text file can be as long as you want.

Geektool command:
For Color Output
Code:
~/bin/geektool/tickerv2.sh -c ~/bin/geektool/tickerlist.txt
or
For Non-Color Output
Code:
~/bin/geektool/tickerv2.sh -n ~/bin/geektool/tickerlist.txt
This is how I have it set up on my system, make updates to the script and code to match your setup.

Things of note:
- The bash script throws the HTML on a per stock basis into a folder in /tmp, to get working initially, run the following commands from the Terminal.
Code:
mkdir /tmp/geektool
touch /tmp/geektool/stocklist

The attachments show the two options for the code.
 

Attachments

  • stocklist_geektool.png
    stocklist_geektool.png
    237.6 KB · Views: 175
  • tickerscreenie2.png
    tickerscreenie2.png
    45.3 KB · Views: 5,074
While I don't know why +%P isn't working, you could always use translate to turn the characters into lowercase after the fact...

Code:
date "+%p" | tr [A-Z] [a-z]

Awesome.. that did the trick!

mike
 
my newest geektool set-up

here's my star wars themed desktop, just finished setting it up.

let me know what i should change/what you like etc.
<3
 

Attachments

  • geektool2.gif
    geektool2.gif
    415.8 KB · Views: 324
I like that a lot; nice behind-the-scenes photo.

Only thing I would change though, is to make the date a brighter color or white against that platform behind Vader. Also, don't know if it's possible, but having the weather icons always be in black & white would be very cool.
 
I like that a lot; nice behind-the-scenes photo.

Only thing I would change though, is to make the date a brighter color or white against that platform behind Vader. Also, don't know if it's possible, but having the weather icons always be in black & white would be very cool.

You know, I thought about that. It sure does look nice with the grey moon. No idea how I'd make them all black & white, i think that would constitute making my own weather images...and I wouldn't know how to do that.

On second thought, would it work to create a black image, and down the opacity on it? I'm gonna give that a try.

I did make the date white, it looks much better.
Will post update with grey images in a minute...
 
Nah, that didn't work too well.
If anyone has any other ideas, lemme know. It'd be awesome to have black and white weather images.

Attached are final version and the one with black overlay.


EDIT: One last thing, does anyone know how to make the hard drive space display as 40GB instead of 40GI?
 

Attachments

  • geektool3.gif
    geektool3.gif
    417 KB · Views: 486
  • geektool4.gif
    geektool4.gif
    418.1 KB · Views: 375
my brand new desktop!
finished it 5 min ago! :cool:

I would love it if you could be so kind as to post your scripts? I'm especially interested in the way you set up the three months worth of calendar and the fact of the day one.

Thanks in advance.
 
I would love it if you could be so kind as to post your scripts? I'm especially interested in the way you set up the three months worth of calendar and the fact of the day one.

Thanks in advance.

theres 2 scripts: one for today's date, and one for the rest. thats why i can get two colors easily. you have to put them in a texedit file, then save it wherever you want... its a .sh file.

heres the month :
Code:
#!/bin/bash
calendar=`cal`
heute=`date +%e`
if [ "$heute" -lt 10 ]; then
	heute=${heute:1:1}
fi
monat=`date +%m`
jahr=`date +%Y`
for (( i=1; i<10; i++ )); do
	if [ "$i" -eq "$heute" ]; then
	echo "		"
	else
	echo -ne `date -j $monat'0'$i'0405'$jahr +%a`
	echo -ne "		"
	echo $i
	fi
done
for (( i=10; i<=${calendar:(-2)}; i++ )); do
	if [ "$i" -eq "$heute" ]; then
	echo "		"
	else 
	echo -ne `date -j $monat$i'0405'$jahr +%a`
	echo -ne "		"
	echo $i
	fi
done

same thing for today for today:
Code:
#!/bin/bash
calendar=`cal`
heute=`date +%e`
if [ "$heute" -lt 10 ]; then
	heute=${heute:1:1}
fi
monat=`date +%m`
jahr=`date +%Y`
for (( i=1; i<10; i++ )); do
	if [ "$i" -eq "$heute" ]; then
	echo -ne `date -j $monat'0'$i'0405'$jahr +%a`
	echo -ne "  "
	echo $i
	exit
	else
	echo " "
	fi
done
for (( i=10; i<=${calendar:(-2)}; i++ )); do
	if [ "$i" -eq "$heute" ]; then
	echo -ne `date -j $monat$i'0405'$jahr +%a`
	echo -ne " "
	echo $i
	exit
	else 
	echo " "
	fi
done

and the only think that you have to do on geektool is write the path of the file ("/Users/you/Documents/geektool/vertical_calendar_date_only.sh" without the quote marks.) and no the scripts are not from me... i've found them somewhere on internet (or someone put the link here a few months ago... cant remember) and the words are in german, and it wont change anything.

for the +1 and -1 months calendars here you go:
previous
Code:
#!/bin/bash

# Helper function to display a month in the past or future
Cal() { cal $(date -v$1m '+%m %Y') | sed 's/^/ /';}



# Previous month
Cal -1

same thing for the next month, but with +1 instead of -1 on the last line. you can put +1000 if you want its gonna work... (once again, i've found the script somewhere... i know im a thief... :D)

for any other code, just ask me!
 
brenm666, thank you for your quick answer.

Unfortunately the scripts don't seem to work for me. Now, this is probably because I'm new to GeekTool and have no knowledge/experience of code and have probably done something wrong.

I've saved the code you quoted as .sh files in TextEdit, after converting them to plain text.

Then I create a new 'Shell' Geeklet by dragging it to my desktop and put "/Users/MyUser/Documents/GeekTool/Vertical_calendar_full.sh" in the command line (without the quotes), which is the file path to where I have the scripts saved.

When I do this, nothing happens. And the 'status feedback image' is red.

Is there something further I need to do, or have I already gone wrong?

Thanks again for your help with this, and I must say your desktop looks fantastic the way you've set it up!
 
brenm666, thank you for your quick answer.

Unfortunately the scripts don't seem to work for me. Now, this is probably because I'm new to GeekTool and have no knowledge/experience of code and have probably done something wrong.

I've saved the code you quoted as .sh files in TextEdit, after converting them to plain text.

Then I create a new 'Shell' Geeklet by dragging it to my desktop and put "/Users/MyUser/Documents/GeekTool/Vertical_calendar_full.sh" in the command line (without the quotes), which is the file path to where I have the scripts saved.

When I do this, nothing happens. And the 'status feedback image' is red.

Is there something further I need to do, or have I already gone wrong?

Thanks again for your help with this, and I must say your desktop looks fantastic the way you've set it up!

thanks!

in geektool, did you put the right path? including the name of the file? double check... pretty sure thats the problem... also, what do you mean by "converting them to plain text"? the only thing you have to do is a copy paste of the code, and then save it as an .sh file... this should work...

did the 2 calendars work?
 
thanks!

in geektool, did you put the right path? including the name of the file? double check... pretty sure thats the problem... also, what do you mean by "converting them to plain text"? the only thing you have to do is a copy paste of the code, and then save it as an .sh file... this should work...

did the 2 calendars work?

Yeh, I'm certain the file path is right, I copied it from the 'Get Info' of the file.

Uhm, using text edit it automatically formats the document as rich text (.rtf) and you have to convert it to plain text (.txt) before you can save it as a shell script (.sh).

Any other idea why they might not be working? And alas, no, none of the scripts run.

Thanks again.
 
Yeh, I'm certain the file path is right, I copied it from the 'Get Info' of the file.

Uhm, using text edit it automatically formats the document as rich text (.rtf) and you have to convert it to plain text (.txt) before you can save it as a shell script (.sh).

Any other idea why they might not be working? And alas, no, none of the scripts run.

Thanks again.

so lets say that on geektool, you have "/PATH/TO/FILE/month.sh"
in finder, when you go to your folder, you have a file named "month.sh"
in the file, youre suppose to put everything, from the first line (#!/bin/bash) to the last (done)

if that doesnt work, well i dont know! :confused:

and for the 2 months calendar, what did you put in the geektool command line? ("..." to see everything)

edit: and no need to save it in rtf, then txt, then sh. just save it (without anything), then in finder, rename it and add the .sh
 
Yeh, I'm certain the file path is right, I copied it from the 'Get Info' of the file.

Uhm, using text edit it automatically formats the document as rich text (.rtf) and you have to convert it to plain text (.txt) before you can save it as a shell script (.sh).

Any other idea why they might not be working? And alas, no, none of the scripts run.

Thanks again.

You need to make the scripts executable. In a terminal window (not geektool) you need to run the following command:
Code:
chmod +x /path/to/your/script.sh
 
Nah, that didn't work too well.
If anyone has any other ideas, lemme know. It'd be awesome to have black and white weather images.

Attached are final version and the one with black overlay.


EDIT: One last thing, does anyone know how to make the hard drive space display as 40GB instead of 40GI?

At the end of your code to grab the disk space, add the following:
Code:
 | sed "s/Gi/GB/"

I'm assuming the original script outputs the disk space as Gi (mine did that), so that's why I left it lowercase. If it doesn't work, make the "i" in the sed command uppercase.
 
You need to make the scripts executable. In a terminal window (not geektool) you need to run the following command:
Code:
chmod +x /path/to/your/script.sh

Thank you, that fixed the problem and lets me run it.

brenm666, the +1/-1 calendar scripts run just fine thank you. Would it be possible to get the 'fact of the day' style script you're running as well? Thanks again.

However, there is an interesting quirk with the vertical calendar script that I wonder if there is a solution to.

When I have the vertical calendar with all the dates except todays at font size 12 everything is fine, but when I increase the font size the alignment of the date numbers gets messed up. I think the easiest way to explain is with the below screenshots.

As you can see the 'box' which the script is running in is big enough, and I have no idea why font size would mess with the formatting of a script. As I change the size the number jump to different positions, returning to their original when I put it back in size 12.

Any ideas?

Thanks for the help.
 

Attachments

  • Size 12.png
    Size 12.png
    59.3 KB · Views: 238
  • Size 13.png
    Size 13.png
    62.6 KB · Views: 163
  • Size 14.png
    Size 14.png
    64 KB · Views: 185
Thank you, that fixed the problem and lets me run it.

brenm666, the +1/-1 calendar scripts run just fine thank you. Would it be possible to get the 'fact of the day' style script you're running as well? Thanks again.

However, there is an interesting quirk with the vertical calendar script that I wonder if there is a solution to.

When I have the vertical calendar with all the dates except todays at font size 12 everything is fine, but when I increase the font size the alignment of the date numbers gets messed up. I think the easiest way to explain is with the below screenshots.

As you can see the 'box' which the script is running in is big enough, and I have no idea why font size would mess with the formatting of a script. As I change the size the number jump to different positions, returning to their original when I put it back in size 12.

Any ideas?

Thanks for the help.

fact of the day:
Code:
curl http://www.infoplease.com/rss/dayinhistory.rss | grep CDATA | sed -e 's/\(.*\[\)//' -e 's/\].*//'

for the font size problem, i have absolutely no clue... i know that if you put it at 24, or under 12 it works, but i really dont know why... putting an extra tab didnt work... :confused:
ill think about it and let you know!
 
When I have the vertical calendar with all the dates except todays at font size 12 everything is fine, but when I increase the font size the alignment of the date numbers gets messed up. I think the easiest way to explain is with the below screenshots.

As you can see the 'box' which the script is running in is big enough, and I have no idea why font size would mess with the formatting of a script. As I change the size the number jump to different positions, returning to their original when I put it back in size 12.

Any ideas?

Thanks for the help.

That is happening because of the font you are using. Certain fonts will only work up to a certain size properly before formatting becomes an issue. For calenders, if you want to maintain proper font alignment you must select and use a "Fixed Width" font.
 
fact of the day:
Code:
curl http://www.infoplease.com/rss/dayinhistory.rss | grep CDATA | sed -e 's/\(.*\[\)//' -e 's/\].*//'

for the font size problem, i have absolutely no clue... i know that if you put it at 24, or under 12 it works, but i really dont know why... putting an extra tab didnt work... :confused:
ill think about it and let you know!

and

That is happening because of the font you are using. Certain fonts will only work up to a certain size properly before formatting becomes an issue. For calenders, if you want to maintain proper font alignment you must select and use a "Fixed Width" font.

Thanks for that.

Size 24 actually fits my screen perfectly, so I guess that kinda avoids the issue, so no worries!

One last thing, is there a way to force a line break in the fact of the day script? So that if the quote is longer than the box I've allocated it puts it onto a second line, rather than simply running off the box and not being seen?
 
One last thing, is there a way to force a line break in the fact of the day script? So that if the quote is longer than the box I've allocated it puts it onto a second line, rather than simply running off the box and not being seen?

Yes, in geektool, when you are editing the file properties, there is a checkbox at the bottom called "Force Carriage Return". Enable that and it will wrap the text that goes over.
 
Yes, in geektool, when you are editing the file properties, there is a checkbox at the bottom called "Force Carriage Return". Enable that and it will wrap the text that goes over.

Cheers man.

And thank you to everyone who helped, it's much appreciated.
 
Status
Not open for further replies.
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.