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.
Anyone have a proper way to display CPU usage?

I tried:

Code:
top -l2 | grep "CPU usage" | cut -c 1-11,25-26

with 'cut' to remove what I don't want displayed but seeing as the number fluctuates, the overall percentage sometimes gets cut off.

Anyone have a solution?

r0dxlc.png

Or if you want the top 5 processes along with the user it's running under:
ps -arcwwxo "command %cpu ruser" | head -6
 
Hey everyone,

I put a lot of effort into this setup. I wanted a clean look that focuses on my music collection. I wanted something pretty to look at that has all the relevant music info (especially lyrics) and is interactive.

I am using Bowtie primarily to manage itunes. Everything is set up with keyboard commands rather than actual player controls. I used geektool scripts for star ratings, song titles, artist, last fm, upcoming itunes, and lyrics. I used "Get Lyrical" to actively tag songs as I play them.

Keyboard commands allow me to go forward/back, play pause, and most importantly star ratings up and down in real time.

I decided to not use cover art b/c overall I decided it detracted too much from the aesthetics. I also decided to forego all non-music relative scripts b/c once again I thought it took away from the cleanliness. I have other setups I use that are very info intensive but I find myself liking this one way more.

If anyone needs any help with these sort of scripts just let me know.

Cheers
 

Attachments

  • mydesktop.jpeg
    mydesktop.jpeg
    587.9 KB · Views: 343
How do you guys attach a thumbnail image? I'm doing something wrong...

When you are making your post, look below the text box to "manage attachments" and then browse for file location and upload. Do not forget to upload before closing the pop up window.
 
Hey everyone,

I put a lot of effort into this setup. I wanted a clean look that focuses on my music collection. I wanted something pretty to look at that has all the relevant music info (especially lyrics) and is interactive.

I am using Bowtie primarily to manage itunes. Everything is set up with keyboard commands rather than actual player controls. I used geektool scripts for star ratings, song titles, artist, last fm, upcoming itunes, and lyrics. I used "Get Lyrical" to actively tag songs as I play them.

Keyboard commands allow me to go forward/back, play pause, and most importantly star ratings up and down in real time.

I decided to not use cover art b/c overall I decided it detracted too much from the aesthetics. I also decided to forego all non-music relative scripts b/c once again I thought it took away from the cleanliness. I have other setups I use that are very info intensive but I find myself liking this one way more.

If anyone needs any help with these sort of scripts just let me know.

Cheers

which script did you use for the upcoming songs? is it good when you work on shuffle? or is it working with lastfm?
thanks!
 
Having trouble with putting all on one line

Hi antcuc,

It's actually just a simple workaround. You make two scripts laid on top of each other, one in green and one in red. Then you configure the red one not to print anything if the stock has gone up and green one not to print anything if the stock has gone down.

So, take a general stock quote script. Here's mine for the DOW:

curl http://www.google.ca/finance?q=INDEXDJX:.DJI | sed -n '/price-panel style/,/ Close/p' | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'| sed '/^$/d' | sed -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' | head -1 | sed 's/^/DOW: /g'

That outputs: DOW: 9,256.26 -24.71 (-0.27%)

Now copy it so you have two.

Then add this to the end of the one you make red:
| sed -n '/-/p'
That makes it so it will only print lines where a "-" appears, so it'll only give the output if things went south that day.

Then, add this one to the one that you make green:
| sed '/-/d'
That'll delete the output if a "-" appears, so it'll only print if the index went up or stayed put.

Since, you're just modifying the format of the two scripts, you can have any change occur depending on whether things went up or down. You could have the background change colour or tranparency. You could change the font, size, whatever.

Hope that helps, let me know if you have any other questions.

(Oh yeah, and to make this work for other stocks, you just have to change the link in the original curl script, and then change the label that you give it at the end of the script)



Heres my code:


curl http://www.google.ca/finance?q=INDEXDJX:.DJI | sed -n '/price-panel style/,/ Close/p' | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'| sed '/^$/d' | sed -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' | head -1 | sed 's/^/DOW: /g' & curl http://www.google.com/finance?q=F | sed -n '/price-panel style/,/ Close/p' | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'| sed '/^$/d' | sed -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' | head -1 | sed 's/^/F: /g' & curl http://www.google.ca/finance?q=NASDAQ:MSFT | sed -n '/price-panel style/,/ Close/p' | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'| sed '/^$/d' | sed -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' | head -1 | sed 's/^/MSFT: /g'


it puts everything vertical, but im trying to have it all on one line. what am i missing?

thanks in advanced
 

Attachments

  • Screenshot2010-06-18at23637PM.png
    Screenshot2010-06-18at23637PM.png
    698.1 KB · Views: 243
New geektool geek

I discovered geektool a few days ago and have spent a good deal of my free time the last few days tinkering with it.

I was a big time Konfabultor then Yahoo Widgets user, but I always felt that program didn't give enough for what it took. Sure, it was pretty and even useful, but the resources man!

Forward to Geektool and all of the sudden I am brushing up on my Apple script skills to add some new wrinkles to my desktop.

First, I want to thank this thread. I gleaned much of the foundation of my weather alert script here. Second, I thank anyone who has given there knowledge and ideas to the geektool community - there are some truly fantastic desktops out there!

Check out the screenshot below. The font is Helvetica Neue

Most of it is obvious. I decided I wanted to use Applescript for the iTunes output (and yes, I know about Bowtie) just to avoid yet another program. It is a bit more complex then some of the examples, so here is the code if anyone wants to use (or improve!) it:

Code:
--This script borrows heavily in concept and form from the original "iTunesInfo.scpt for geektool"
-- This determines the amount of info this script returns.
-- Set to "enhanced" for track rating, album, and run times in addition to title/artist
-- Set to "enhanced SL" for enhanced in a single line
-- Set to "enhancedalt1" for enahnced with static time of track
-- If neither option is selected, it will default to simple Title | Artist display

set displayLogic to "enhancedalt1"

tell application "System Events"
	set powerCheck to ((application processes whose (name is equal to "iTunes")) count)
	if powerCheck = 0 then
		return "iTunes inactive"
	else
		
		-- This section moved to avoid launching iTunes when the script is run.		
		tell application "iTunes"
			try
				set playerstate to (get player state)
			end try
			if playerstate = paused then
				set trackStatus to "❚❚ "
			else
				set trackStatus to "❯ "
			end if
			
			try
				set trackID to the current track
				set trackName to the name of trackID
				set artistName to the artist of trackID
				set albumName to the album of trackID
				
				set tracktime to the time of trackID
				
				set trackdur to the duration of trackID
				set trackdur to round {trackdur}
				
				
				set trackcur to player position
				set trackcur to round {trackcur}
				
				set trackplaycount to the played count of trackID
				
				set ratetrack to the rating of trackID
				if ratetrack < 20 then
					set trackrating to "☆☆☆☆☆"
				else
					if ratetrack < 40 then
						set trackrating to "★☆☆☆☆"
					else
						if ratetrack < 60 then
							set trackrating to "★★☆☆☆"
						else
							if ratetrack < 80 then
								set trackrating to "★★★☆☆"
							else
								if ratetrack < 100 then
									set trackrating to "★★★★☆"
								else
									set trackrating to "★★★★★"
								end if
							end if
						end if
					end if
				end if
				
				if displayLogic = "enhanced" then
					set displaymain to trackStatus & " " & trackName & " | " & artistName & " | " & albumName & "\n" & trackrating & " (" & trackcur & "s of " & trackdur & "s)"
				else if displayLogic = "enhanced SL" then
					set displaymain to trackStatus & " " & trackName & " | " & artistName & " | " & albumName & " " & trackrating & " (" & trackcur & "s of " & trackdur & "s)"
				else if displayLogic = "enhancedalt1" then
					set displaymain to trackStatus & " " & trackName & " | " & artistName & " | " & albumName & "\n" & " (" & tracktime & ")  " & trackrating & "  " & trackplaycount & " plays"
				else
					set displaymain to trackStatus & " " & trackName & " | " & artistName
				end if
			on error
				if playerstate = stopped then
					set trackStatus to "iTunes Stopped"
				end if
				
			end try
		end tell
	end if
end tell

You can tell I am no Applescript guru. I have stood on the backs of genius to achieve the goal. Speaking of standing on the backs of genius, one thing I did miss about Yahoo Widgets was an old widget that displayed weather alerts. In fact, it was searching to see if this was possible that I stumbled onto this thread. My script returns the top 2 alerts from here:

http://www.weather.gov/alerts/

It uses the county code to work, and I have played around with it enough to imagine it should work well enough for everyone. Just drop the code in theLoc variable.

Code:
-- Change this location to the county code at http://www.weather.gov/alerts/
set theLoc to "INC163"


set shell1 to "curl \""
set shell2 to "http://www.weather.gov/alerts-beta/wwaatmget.php?x="
set shell3 to "\""

tell application "Finder"
	set web_content to do shell script (shell1 & shell2 & theLoc & shell3)
end tell

--Get Alert1
set AppleScript's text item delimiters to "<entry>"

set count1 to count of text items of web_content

if count1 ≥ 2 then
	try
		set warn1 to text item 2 of (web_content as string)
		set AppleScript's text item delimiters to "<title>"
		set warn1 to text item 2 of warn1
		set AppleScript's text item delimiters to " issued"
		set warntitle1 to text item 1 of warn1
		
		--distill the output to a date and time stamp
		set AppleScript's text item delimiters to "<cap:expires>"
		set warnTD to text item 2 of warn1
		set AppleScript's text item delimiters to "</cap:expires>"
		set warnTD to text item 1 of warnTD
		
		--Get the expiration day/time
		set AppleScript's text item delimiters to "-"
		set warnday_y to text item 1 of warnTD
		set warnday_m to text item 2 of warnTD
		set warnday_d to text 1 through 2 of text item 3 of warnTD
		
		set warnday to (warnday_m & "/" & warnday_d & "/" & warnday_y)
		
		set AppleScript's text item delimiters to "T"
		set warntime_h to text 1 through 2 of text item 2 of warnTD
		set AppleScript's text item delimiters to ":"
		set warntime_m to text item 2 of warnTD
		
		set warndate to date warnday
		set warndate to warndate + (warntime_h * hours) + (warntime_m * minutes)
		
		-- Do the math between the current time and the expiration time
		
		set curDate to the current date
		set difTime to warndate - curDate
		
		set exp_h1 to difTime div hours
		set exp_m1 to difTime mod hours div minutes
		
		
		--Get Alert 2
		
		if count1 ≥ 3 then
			set AppleScript's text item delimiters to "<entry>"
			
			set warn2 to text item 3 of (web_content as string)
			set AppleScript's text item delimiters to "<title>"
			set warn2 to text item 2 of warn2
			set AppleScript's text item delimiters to " issued"
			
			set warntitle2 to text item 1 of warn2
			
			--Distill the output to a date and time stamp
			
			set AppleScript's text item delimiters to "<cap:expires>"
			set warnTD2 to text item 2 of warn2
			set AppleScript's text item delimiters to "</cap:expires>"
			set warnTD2 to text item 1 of warnTD2
			
			--Get the expiration day/time
			set AppleScript's text item delimiters to "-"
			set warnday_y2 to text item 1 of warnTD2
			set warnday_m2 to text item 2 of warnTD2
			set warnday_d2 to text 1 through 2 of text item 3 of warnTD2
			
			set warnday2 to (warnday_m2 & "/" & warnday_d2 & "/" & warnday_y2)
			
			set AppleScript's text item delimiters to "T"
			set warntime_h2 to text 1 through 2 of text item 2 of warnTD2
			set AppleScript's text item delimiters to ":"
			set warntime_m2 to text item 2 of warnTD2
			
			set warndate2 to date warnday2
			set warndate2 to warndate2 + (warntime_h2 * hours) + (warntime_m2 * minutes)
			
			-- Do the math between the current time and the expiration time
			
			set curDate2 to the current date
			set difTime2 to warndate2 - curDate2
			
			set exp_h2 to difTime2 div hours
			set exp_m2 to difTime2 mod hours div minutes
		else
			set warntitle2 to ""
		end if
		
		
		--Output Display
		if count1 = 2 then
			set displaymain1 to warntitle1 & " (" & exp_h1 & "h " & exp_m1 & "m)"
		else if count1 ≥ 3 then
			set displaymain1 to warntitle1 & " (" & exp_h1 & "h " & exp_m1 & "m)\n" & warntitle2 & " (" & exp_h2 & "h " & exp_m2 & "m)"
		end if
		
	on error
		return ""
		
	end try
else
	return ""
end if

Again, there is probably a more elegant way to do this. I choose to create this because the XML data exposes a ton more data about the alert than just parsing it from the main forecast page.

That's about it. Let me know what you think or if you have any questions or problems with the scripts.
 

Attachments

  • geektool_screen_2010_06_23_2308.jpg
    geektool_screen_2010_06_23_2308.jpg
    102.6 KB · Views: 317
Most of it is obvious. I decided I wanted to use Applescript for the iTunes output (and yes, I know about Bowtie) just to avoid yet another program. It is a bit more complex then some of the examples, so here is the code if anyone wants to use (or improve!) it:
Wow, I didnt even know you could take all this information from iTunes! Is there a list of all the properties we can find? Properties like upcoming songs? :)
And i totally agree with you. Bowtie is nice, but its another program running... Plus, we can do much more with Applescript!
Heres my version! (the only thing Ive changed was the message when iTunes is paused) Just put it right after enhancedalt1!
Code:
else if displayLogic = "enhancedalt2" then
					if playerstate = paused then
						set displaymain to "❚❚ "
					else
						set displaymain to trackStatus & " " & trackName & " | " & artistName & " | " & albumName & "
   " & " (" & tracktime & ") " & "- " & trackrating & " - " & trackplaycount & " plays"
					end if
But just a question : where did you get the pause/play characters?

and for the weather alerts, well i live in canada so yeah... its useless for me :D

and thanks for the code!
 
Wow, I didnt even know you could take all this information from iTunes! Is there a list of all the properties we can find? Properties like upcoming songs? :)
And i totally agree with you. Bowtie is nice, but its another program running... Plus, we can do much more with Applescript!
Heres my version! (the only thing Ive changed was the message when iTunes is paused) Just put it right after enhancedalt1!
Code:
else if displayLogic = "enhancedalt2" then
					if playerstate = paused then
						set displaymain to "❚❚ "
					else
						set displaymain to trackStatus & " " & trackName & " | " & artistName & " | " & albumName & "
   " & " (" & tracktime & ") " & "- " & trackrating & " - " & trackplaycount & " plays"
					end if
But just a question : where did you get the pause/play characters?

and for the weather alerts, well i live in canada so yeah... its useless for me :D

and thanks for the code!

You can get nearly every value from a track in iTunes. Launch Script Editor and then select open dictionary. From there, select iTunes and get ready for information overload.

I got the characters from the Character Viewer under the Keyboard Preference Pane. Again, a ton more symbols to choose.

Sorry that the alert code is US only. I am toying with the idea of rebuilding my weather scripts from scratch as I am currently using three different programming languages to get the job done. If I do, I will look into making it more global.
 
You can get nearly every value from a track in iTunes. Launch Script Editor and then select open dictionary. From there, select iTunes and get ready for information overload.

I got the characters from the Character Viewer under the Keyboard Preference Pane. Again, a ton more symbols to choose.

Sorry that the alert code is US only. I am toying with the idea of rebuilding my weather scripts from scratch as I am currently using three different programming languages to get the job done. If I do, I will look into making it more global.

well thats good to know (both the dictionary and the Character Viewer)! thanks! a little technical question for my personal understanding: why did you put a "try"? :)
and for the weather, its ok. the script i use for it only uses two languages! go back one or two pages and you'll find a link i posted of a youtube video. it's all there!

also, anyone knows if its possible to create a "hyperlink" with Applescript and Geektool? (you click on a word and it does something: pausing iTunes for example)
 
Answer and Question...

well thats good to know (both the dictionary and the Character Viewer)! thanks! a little technical question for my personal understanding: why did you put a "try"? :)
and for the weather, its ok. the script i use for it only uses two languages! go back one or two pages and you'll find a link i posted of a youtube video. it's all there!

also, anyone knows if its possible to create a "hyperlink" with Applescript and Geektool? (you click on a word and it does something: pausing iTunes for example)

No problem, I am happy to be able to help, especially in the light of all the knowledge I have gleaned from this thread (and several other sites) over the past few days.

I think hyperlinking is out of the realm of Geektool. Even if you passed it a link from the shell or Applescript it would need another layer of interactivity to make it function. If you really need that functionality, check out Yahoo Widgets. I was too chicken to start programming my own widgets to do so ;)

That Youtube video was quite an elegant way to display the weather icon. The reason I have three going right now is because there is a weather script floating around out there coded in python that can return separate variables. It's what I use for my current temp. The forecast is from a script that also grabs the weather icon and the location is from yet another script.

And that brings up a question for anyone that can answer it. Would it be advantageous to use one script to parse the weather data out to separate text files and then use multiple file geeklets to display them? It seems like every compelling weather setup I have seen uses different text sizes/colors/transparencies so this approach could simplify the process.

That is, unless there is a good reason not to do it this way :). That's the next thing I am playing with.
 
a little technical question for my personal understanding: why did you put a "try"? :)

Sorry I missed explaining this. The Try statement allows you to elegantly dump out of a error in the programming. Because the script draws from and XML that could change anytime, it was best to provide a way for the script to exit cleanly.
 
Im having a bit of trouble with applescript. When I want to display the name of a playlist, whats my code? Knowing that "playlist" is a class and that "name" is the property. This is what ive tried :
Code:
set trackplaylist to the playlist of trackID
set trackplay to the name of trackplaylist
Code:
set trackplaylist to the playlist name of trackID
Code:
set trackplaylist to the name of the playlist of trackID
and nothing worked... :mad:

thanks!
 
Im having a bit of trouble with applescript. When I want to display the name of a playlist, whats my code? Knowing that "playlist" is a class and that "name" is the property. This is what ive tried :
Code:
set trackplaylist to the playlist of trackID
set trackplay to the name of trackplaylist
Code:
set trackplaylist to the playlist name of trackID
Code:
set trackplaylist to the name of the playlist of trackID
and nothing worked... :mad:

thanks!

This works for the current playlist:

Code:
tell application "iTunes"
	set playlist1 to name of current playlist
end tell

There has to be a way to get the playlist name of another track besides the one you are currently using, but I don't know why you would want to.
 
iTunes Previous and Next tracks

This is more of a proof of concept but since I have seen it brought up a few times I decided to take a stab at showing track data for both the previous and next track.

WARNING: These scripts (there are two needed to make it work this way) are resource intensive at a 1 sec interval. On my i5 MBP, the scripts alone takes around 5% of the CPU and combined with Geektool makes the CPU stay around 10-12% usage. Not a big deal, but the usage is constant.

I modified my previous iTunes code as I didn't see the need to display some of the data at a higher size. Here:

Code:
tell application "System Events"
	set powerCheck to ((application processes whose (name is equal to "iTunes")) count)
	if powerCheck = 0 then
		return "iTunes inactive"
	else
		
		-- This section moved to avoid launching iTunes when the script is run.		
		tell application "iTunes"
			try
				set playerstate to (get player state)
			end try
			if playerstate = paused then
				set trackStatus to "❚ ❚ "
			else
				set trackStatus to "❯ "
			end if
			
			try
				set trackID to the current track
				set trackname to the name of trackID
				set artistName to the artist of trackID
				set albumName to the album of trackID
				
				set tracktime to the time of trackID
				
				--set trackdur to the duration of trackID
				--set trackdur to round {trackdur}
				
				
				--set trackcur to player position
				--set trackcur to round {trackcur}
				
				--set trackplaycount to the played count of trackID
				
				set ratetrack to the rating of trackID
				if ratetrack < 20 then
					set trackrating to "☆☆☆☆☆"
				else
					if ratetrack < 40 then
						set trackrating to "★☆☆☆☆"
					else
						if ratetrack < 60 then
							set trackrating to "★★☆☆☆"
						else
							if ratetrack < 80 then
								set trackrating to "★★★☆☆"
							else
								if ratetrack < 100 then
									set trackrating to "★★★★☆"
								else
									set trackrating to "★★★★★"
								end if
							end if
						end if
					end if
				end if
				
				set displaymain to trackStatus & " " & trackname & " | " & artistName & " " & trackrating & " (" & tracktime & ")"
				
			on error
				if playerstate = stopped then
					set trackStatus to "iTunes Stopped"
				end if
				
			end try
		end tell
	end if
end tell

That's still the current track. Place it in it's own geeklet. Now for the new stuff:

Code:
tell application "iTunes"
	try
		
		set curTrack to current track
		set curDex to index of current track
		
		set curPL to current playlist
		
		set prevDex to curDex - 1
		set nextdex to curDex + 1
		
		if prevDex > 0 then
			set prevName to name of track prevDex of curPL
			set prevArtist to artist of track prevDex of curPL
			set prevdisplay to prevName & " by " & prevArtist
		else
			set prevdisplay to "(start of playlist)"
		end if
		
		try
			set nextName to name of track nextdex of curPL
			set nextArtist to artist of track nextdex of curPL
			set nextdisplay to nextName & " by " & nextArtist
		on error
			set nextdisplay to "(end of playlist)"
		end try
		
		set jukedisplay to prevdisplay & "\n \n \n" & nextdisplay
		
	on error
		return ""
	end try
end tell

This returns the track title and the track artist for both the previous and next track. I originally had it broken into 2 separate scripts, but that was getting silly in terms of CPU usage. I placed a space in the output of the script in order to overlay the current track info, thereby making a little playlist on the desktop.

Note, I could have made this all into one script and I still might, but I like the aesthetic of a different font size/transparency.

Suggestions, comments - post them here!
 

Attachments

  • screen_2010_06_25_1530.jpg
    screen_2010_06_25_1530.jpg
    56.6 KB · Views: 231
That's still the current track. Place it in it's own geeklet. Now for the new stuff:

Code:
tell application "iTunes"
	try
		
		set curTrack to current track
		set curDex to index of current track
		
		set curPL to current playlist
		
		set prevDex to curDex - 1
		set nextdex to curDex + 1
		
		if prevDex > 0 then
			set prevName to name of track prevDex of curPL
			set prevArtist to artist of track prevDex of curPL
			set prevdisplay to prevName & " by " & prevArtist
		else
			set prevdisplay to "(start of playlist)"
		end if
		
		try
			set nextName to name of track nextdex of curPL
			set nextArtist to artist of track nextdex of curPL
			set nextdisplay to nextName & " by " & nextArtist
		on error
			set nextdisplay to "(end of playlist)"
		end try
		
		set jukedisplay to prevdisplay & "\n \n \n" & nextdisplay
		
	on error
		return ""
	end try
end tell

This returns the track title and the track artist for both the previous and next track. I originally had it broken into 2 separate scripts, but that was getting silly in terms of CPU usage. I placed a space in the output of the script in order to overlay the current track info, thereby making a little playlist on the desktop.

Note, I could have made this all into one script and I still might, but I like the aesthetic of a different font size/transparency.

Suggestions, comments - post them here!
That's pretty awesome... But is there a way to show up the previous, but more importantly, the next song to actually play? I've looked on the dictionary, and I couldnt find anything... By the way, thanks a lot for the answers shomann... trust me you help me a lot! Like for the playlist: it worked perfectly!!! Do you know a website that explains Applescript? Id like to learn on my own without asking questions every 2 seconds! ;)

And for your multiple weather script... Wouldnt this use a lot more CPU than just one script?
 
Status
Not open for further replies.
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.