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.
Does anyone know how to pull out the quote from MS Encarta but il goes automatically on a new line if the shell's width isn't enough ?.

Thx in advance
 
I just reworked my script a little so I only have one now for iTunes thanks to you asking and me wanting to make it simple for people to implement.

Download the attached .zip file. Open it up. Inside are the script and the exported Geeklet. Move the script to wherever you want (remember where!). Next double-click the Geeklet to open it in Geektool.

All you should have to do is edit the Command box with your own path from:

osascript /Users/brian/Documents/Customization/GeekTool/iTunesInfo.scpt

to

osascript /Users/YOU/where/it/is/iTunesInfo.scpt


This script will show the following info:
Song
Artist

Lyrics


*** iTunes does NOT need to be running for this to work. A big plus in my book!

*** Also, when iTunes is not open, NOTHING is showing. Another plus in my book.

[EDIT- I've updates all these scripts at the bottom of this page]

maybe it's just me, but most itunes scripts cause iTunes to relaunch i quit, apparently it's something to do with the itunes helper app in snow leopard (that launches itunes when an ipod etc is detected). the "system events" powercheck thingy doesn't overcome it (at least for me), probably because the helper is in the same "itunes" bundle as iTunes. reducing the refresh rate for my itunes shells decreased the chance of iTunes relaunching, but that's wasn't very practical for some of the things i want to show (e.g. track progression), and it didn't overcome the problem completely... so i've been looking for scripts that do, and modifying ones i already had based on what i found.

i'm using this script now to display iTunes info (track, artist, album) (modified from http://www.leancrew.com/all-this/2006/07/off-track/ and http://forums.mactalk.com.au/18/51067-learning-love-geektool-primer-part-2-a.html)

(to use, copy into textedit or equivalent, save as .scpt, then use the shell script below to point geektool to the script file)

Code:
set notify to " " 
tell application "iTunes"
	if player state is playing then
		set who to artist of current track as string
		set what to name of current track as string
		set onwhat to album of current track as string
		set trackPaused to ""
		set notify to "Track  : " & what & trackPaused & "
Artist : " & who & "
Album  : " & onwhat
	end if
	if player state is paused then
		set who to artist of current track as string
		set what to name of current track as string
		set onwhat to album of current track as string
		set trackPaused to " (paused)"
		set notify to "Track  : " & what & trackPaused & "
Artist : " & who & "
Album  : " & onwhat
	end if
end tell
notify

but most importantly, to stop itunes relaunching i use this shell script (which is what you put in the geeklet) (from http://www.leancrew.com/all-this/2006/07/off-track/)

Code:
#!/bin/bash
if [[ -n `ps x | grep "iTunes -psn" | grep -v grep` ]]; then 	osascript /Users/<location of script>.scpt 
else
  echo ""
fi



i also use a few other scripts for bits of itunes info, all with the same ^^shell script^^ in geektool

for track number (although it returns the track index, which isn't that helpful when a playlist is shuffled (and you want to know how many tracks in the playlist have been played)... maybe someone has some idea how to overcome that?) (modified from http://forums.whirlpool.net.au/forum-replies-archive.cfm/877240.html)

Code:
set notify to ""
tell application "iTunes"
	if player state is playing then
		set tracksleft to index of current track
		set trackstotal to count every track in current playlist
		set notify to tracksleft & " of " & trackstotal
	end if
	if player state is paused then
		set tracksleft to index of current track
		set trackstotal to count every track in current playlist
		set notify to tracksleft & " of " & trackstotal
	end if
end tell
notify


for the track time (with the ^^shell script^^ above) (modified from http://forums.whirlpool.net.au/forum-replies-archive.cfm/877240.html)

Code:
set notify to ""
tell application "iTunes"
	if player state is playing then
		set timeVal to player position
		set numHours to (timeVal div hours)
		set timeVal to timeVal - (numHours * hours)
		set numMinutes to (timeVal div minutes)
		set numSeconds to timeVal - (numMinutes * minutes)
		set timeStr to "" as string
		if (numHours > 0) then
			if (numHours < 10) then set timeStr to "0"
			set timeStr to (timeStr & numHours)
			set timeStr to (timeStr & ":")
		end if
		if (numMinutes < 10) then set timeStr to (timeStr)
		set timeStr to (timeStr & numMinutes)
		set timeStr to (timeStr & ":")
		if (numSeconds < 10) then set timeStr to (timeStr & "0")
		set timeStr to (timeStr & numSeconds)
		set timetotal to time of current track
		if length of timetotal < 5 then
			set timetotal to timetotal
		end if
		set notify to timeStr & "/" & timetotal
	end if
	if player state is paused then
		set timeVal to player position
		set numHours to (timeVal div hours)
		set timeVal to timeVal - (numHours * hours)
		set numMinutes to (timeVal div minutes)
		set numSeconds to timeVal - (numMinutes * minutes)
		set timeStr to "" as string
		if (numHours > 0) then
			if (numHours < 10) then set timeStr to "0"
			set timeStr to (timeStr & numHours)
			set timeStr to (timeStr & ":")
		end if
		if (numMinutes < 10) then set timeStr to (timeStr)
		set timeStr to (timeStr & numMinutes)
		set timeStr to (timeStr & ":")
		if (numSeconds < 10) then set timeStr to (timeStr & "0")
		set timeStr to (timeStr & numSeconds)
		set timetotal to time of current track
		if length of timetotal < 5 then
			set timetotal to timetotal
		end if
		set notify to timeStr & "/" & timetotal
	end if
end tell
notify


and for a bar showing the track progression (with the ^^shell script^^ above) (still looking for where this one was from originally)

Code:
--- change the max number of dashes to determine length of the progression bar
set maxNumberOfDashes to 75

tell application "iTunes"
	set playerstate to (get player state)
	if playerstate = paused then
		set trackPaused to " (paused)"
	else
		set trackPaused to ""
	end if
	if playerstate = stopped then
		return ""
	end if
	set trackID to the current track
	set trackPosition to the player position
	set trackLength to the duration of trackID
	set theStream to the current stream title as text
end tell

if theStream is not "missing value" then
	set totalData to ""
	repeat maxNumberOfDashes times
		set totalData to "■" & totalData
	end repeat
	return totalData
end if
set numberOfDashes to (trackPosition / trackLength) * maxNumberOfDashes as integer
set totalData to ""
repeat numberOfDashes times
	set totalData to "■" & totalData
end repeat
return totalData
end

none of these are really my own work, i've modified and combined different bits of code from lots of sites until they do what i want :). in all honesty i'm a total noob at scripting etc, going off trail and error and patten recognition, so sorry if things aren't so good, but since it took a far bit of work (and frustration getting itunes to stay closed!) i figured i'd share. i'd be interested to know if other people are having trouble with itunes relaunching when geektool is displaying info, and if they've found a more direct way to overcome it.

this is the overall look of the itunes info displayed on my desktop (album artwork is coversutra... since bowtie disappears off screen with expose).
 

Attachments

  • Screen shot 2009-10-29 at 10.50.19 PM.png
    Screen shot 2009-10-29 at 10.50.19 PM.png
    261.2 KB · Views: 332
@fraylling Wow, thanks for all that. I haven't had a problem with iTunes reopening. I use a script posted a few pages back in this thread that checks if iTunes is running before it tries to pull any information.

Code:
property go1 : false
-- check to see if iTunes is running
tell application "System Events"
	set the process_flag to (exists process "iTunes")
end tell
if the process_flag then
	-- check to see if iTunes is playing
	tell application "iTunes"
		if player state contains playing then set go1 to true
	end tell
	if go1 then
		-- do what you need to do
		tell application "iTunes"
			set foo1 to name of current track
			set foo4 to foo1
		end tell
	end if
end if

And a second on that gets the "current artist" and "current album" because I wanted them to have two separate fonts/font sizes

The progress bar is pretty awesome. The only downside I've seen since switching from Bowtie is I didn't have a progress bar and I can't set the number of stars from the desktop. Seems I've overcome one of those =)
 

Attachments

  • Screen shot 2009-10-29 at 10.06.49 AM.jpg
    Screen shot 2009-10-29 at 10.06.49 AM.jpg
    14.7 KB · Views: 3,060
Blinking clock

Is there anyway to implement a script so you could show the blinking ":" of the clock? I know how to program it but not in unix code. Could somebody help me?
thanks a lot!
 
Is there anyway to implement a script so you could show the blinking ":" of the clock? I know how to program it but not in unix code. Could somebody help me?
thanks a lot!

Use apple script and get the system time. Even second the : is on, odd it is off. I don't know enough about AS to tell you how to do it though.


@fraylling

Originally when I tried your progress bar script iTunes would continousily open. I added a check to see if iTunes was running first and it no longer forces iTunes to say open. I didn't add the check to see if iTunes was playing because if it's not progress = 0 anyways but you'll want to add a check for that to your other scripts also.

Code:
--- change the max number of dashes to determine length of the progression bar
set maxNumberOfDashes to 75
property go1 : false

-- check to see if iTunes is running
tell application "System Events"
	set the process_flag to (exists process "iTunes")
end tell
if the process_flag then
	tell application "iTunes"
		set playerstate to (get player state)
		if playerstate = paused then
			set trackPaused to " (paused)"
		else
			set trackPaused to ""
		end if
		if playerstate = stopped then
			return ""
		end if
		set trackID to the current track
		set trackPosition to the player position
		set trackLength to the duration of trackID
		set theStream to the current stream title as text
	end tell
	
	if theStream is not "missing value" then
		set totalData to ""
		repeat maxNumberOfDashes times
			set totalData to "■" & totalData
		end repeat
		return totalData
	end if
	set numberOfDashes to (trackPosition / trackLength) * maxNumberOfDashes as integer
	set totalData to ""
	repeat numberOfDashes times
		set totalData to "■" & totalData
	end repeat
	return totalData
end if
end
 
Use apple script and get the system time. Even second the : is on, odd it is off. I don't know enough about AS to tell you how to do it though.

I had the same intuition but i don't know how to implement it in AS either, that is why i made this post :)
 
@fraylling


Edited the get time script also. It won't cause iTunes to open any more. You might want to go and add the "totalTime" back. I was lazy and left the extra code in that determines the total time though so it should be easy to fix. Here is the one I'm using.

Code:
set notify to ""
property go : false
--check to see if iTunes is running
tell application "System Events"
	set the process_flag to (exists process "iTunes")
end tell
--run if iTunes is running
if the process_flag then
	tell application "iTunes"
		if player state is playing then
			set timeVal to player position
			set numHours to (timeVal div hours)
			set timeVal to timeVal - (numHours * hours)
			set numMinutes to (timeVal div minutes)
			set numSeconds to timeVal - (numMinutes * minutes)
			set timeStr to "" as string
			if (numHours > 0) then
				if (numHours < 10) then set timeStr to "0"
				set timeStr to (timeStr & numHours)
				set timeStr to (timeStr & ":")
			end if
			if (numMinutes < 10) then set timeStr to (timeStr)
			set timeStr to (timeStr & numMinutes)
			set timeStr to (timeStr & ":")
			if (numSeconds < 10) then set timeStr to (timeStr & "0")
			set timeStr to (timeStr & numSeconds)
			set timetotal to time of current track
			if length of timetotal < 5 then
				set timetotal to timetotal
			end if
			set notify to "| " & timeStr
		end if
		if player state is paused then
			set timeVal to player position
			set numHours to (timeVal div hours)
			set timeVal to timeVal - (numHours * hours)
			set numMinutes to (timeVal div minutes)
			set numSeconds to timeVal - (numMinutes * minutes)
			set timeStr to "" as string
			if (numHours > 0) then
				if (numHours < 10) then set timeStr to "0"
				set timeStr to (timeStr & numHours)
				set timeStr to (timeStr & ":")
			end if
			if (numMinutes < 10) then set timeStr to (timeStr)
			set timeStr to (timeStr & numMinutes)
			set timeStr to (timeStr & ":")
			if (numSeconds < 10) then set timeStr to (timeStr & "0")
			set timeStr to (timeStr & numSeconds)
			set timetotal to time of current track
			if length of timetotal < 5 then
				set timetotal to timetotal
			end if
			set notify to "| " & timeStr
		end if
	end tell
	notify
end if

Thanks a lot for posting the original code!
 

Attachments

  • Screen shot 2009-10-29 at 11.53.59 AM.jpg
    Screen shot 2009-10-29 at 11.53.59 AM.jpg
    20.8 KB · Views: 142
Found a better option (edit: than those previously posted) for highlighting the date in a calendar. I don't use it but thought someone here might want it.
 

Attachments

  • geektool-cal-highlight.png
    geektool-cal-highlight.png
    66.2 KB · Views: 3,173
correct, but for those of us who haven't learned how to do that yet... ;)

check the codes here
http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html

Quick tutorial:
- Open terminal
- Press Ctrl+V
- Press the Esc(ape) key
- You should see this: ^[

The thing is that ^[ is only 1 character - the escape character!

Next let's add the color code we want (green for example)
Green is [32m (see link above)
so we added it and get: ^[[32m (the second '[' is added "normally")

If you did all correctly your terminal should now look green :)
To reset use the reset code: ^[[0m

End of tutorial :)

ps: for the calendar example just use
Code:
cal | sed 's/'`date "+%d"`'/^[[33m&^[[0m/'
and remember, the ^[ is 1 character only that can be introduced as explained above.
So when copy&pasting the code above replace the '^[' (2 characters) with '^[' (escape character)

:)

Edit: the full proof calendar example (the one above only works for day between 10-31 ups! :D) is:
Code:
cal | sed 's/(^|[^0-9])'`date "+%d"`'([^0-9]|$)/^[[33m&^[[0m/'
 
@ cerberus 12

were you using the shell script...

Code:
#!/bin/bash
if [[ -n `ps x | grep "iTunes -psn" | grep -v grep` ]]; then 	osascript /Users/<location of script>.scpt 
else
  echo ""
fi

to check if itunes is running? it should prevent the script opening iTunes

... that being said i think i prefer your solution, the scripts i'd been modifying used things like
Code:
tell application "System Events"
	set powerCheck to ((application processes whose (name is equal to "iTunes")) count)
which i'm theorising recognised the itunes helper as a process containing "iTunes". The check you're using seems to do the trick (so far itunes hasn't bounced back to life on me!) and i think it's much neater having everything in the apple script, i'll probably be editing my other scripts of include it, so thanks! (and thanks to whoever originally posted it).
 
Great scripts. I've added the track time and the progress dashes to my desktop. Very nice. I was afraid geek tool would hog the memory but it is still way under 10.
 
here are the itunes scripts i'm using again, modified so that they wont cause itunes to relaunch while just using the simple shell script

Code:
osascript Users/<location of scpt file>.scpt

track, artist, album
(i put a quote in the brackets of the first line, which is displayed when itunes is closed or stopped)

Code:
set notify to ""
property go : false
tell application "System Events"
	set the process_flag to (exists process "iTunes")
end tell
if the process_flag then
	tell application "iTunes"
		if player state is playing then
			set who to artist of current track as string
			set what to name of current track as string
			set onwhat to album of current track as string
			set trackPaused to ""
			set notify to "Track  : " & what & trackPaused & "
Artist : " & who & "
Album  : " & onwhat
		end if
		if player state is paused then
			set who to artist of current track as string
			set what to name of current track as string
			set onwhat to album of current track as string
			set trackPaused to " (paused)"
			set notify to "Track  : " & what & trackPaused & "
Artist : " & who & "
Album  : " & onwhat
		end if
	end tell
end if
notify

track number

Code:
set notify to ""
property go : false
tell application "System Events"
	set the process_flag to (exists process "iTunes")
end tell
if the process_flag then
	tell application "iTunes"
		if player state is playing then
			set tracksleft to index of current track
			set trackstotal to count every track in current playlist
			set notify to "" & tracksleft & " of " & trackstotal & ""
		end if
		if player state is paused then
			set tracksleft to index of current track
			set trackstotal to count every track in current playlist
			set notify to "" & tracksleft & " of " & trackstotal & ""
		end if
	end tell
	notify
end if

track time

Code:
set notify to ""
property go : false
tell application "System Events"
	set the process_flag to (exists process "iTunes")
end tell
if the process_flag then
	tell application "iTunes"
		if player state is playing then
			set timeVal to player position
			set numHours to (timeVal div hours)
			set timeVal to timeVal - (numHours * hours)
			set numMinutes to (timeVal div minutes)
			set numSeconds to timeVal - (numMinutes * minutes)
			set timeStr to "" as string
			if (numHours > 0) then
				if (numHours < 10) then set timeStr to "0"
				set timeStr to (timeStr & numHours)
				set timeStr to (timeStr & ":")
			end if
			if (numMinutes < 10) then set timeStr to (timeStr)
			set timeStr to (timeStr & numMinutes)
			set timeStr to (timeStr & ":")
			if (numSeconds < 10) then set timeStr to (timeStr & "0")
			set timeStr to (timeStr & numSeconds)
			set timetotal to time of current track
			if length of timetotal < 5 then
				set timetotal to timetotal
			end if
			set notify to timeStr & "/" & timetotal
		end if
		if player state is paused then
			set timeVal to player position
			set numHours to (timeVal div hours)
			set timeVal to timeVal - (numHours * hours)
			set numMinutes to (timeVal div minutes)
			set numSeconds to timeVal - (numMinutes * minutes)
			set timeStr to "" as string
			if (numHours > 0) then
				if (numHours < 10) then set timeStr to "0"
				set timeStr to (timeStr & numHours)
				set timeStr to (timeStr & ":")
			end if
			if (numMinutes < 10) then set timeStr to (timeStr)
			set timeStr to (timeStr & numMinutes)
			set timeStr to (timeStr & ":")
			if (numSeconds < 10) then set timeStr to (timeStr & "0")
			set timeStr to (timeStr & numSeconds)
			set timetotal to time of current track
			if length of timetotal < 5 then
				set timetotal to timetotal
			end if
			set notify to timeStr & "/" & timetotal
		end if
	end tell
	notify
end if

progress bar

Code:
--- change the max number of dashes to determine length of the progression bar
set maxNumberOfDashes to 75
property go1 : false
tell application "System Events"
	set the process_flag to (exists process "iTunes")
end tell
if the process_flag then
	tell application "iTunes"
		set playerstate to (get player state)
		if playerstate = paused then
			set trackPaused to " (paused)"
		else
			set trackPaused to ""
		end if
		if playerstate = stopped then
			return ""
		end if
		set trackID to the current track
		set trackPosition to the player position
		set trackLength to the duration of trackID
		set theStream to the current stream title as text
	end tell
	
	if theStream is not "missing value" then
		set totalData to ""
		repeat maxNumberOfDashes times
			set totalData to "■" & totalData
		end repeat
		return totalData
	end if
	set numberOfDashes to (trackPosition / trackLength) * maxNumberOfDashes as integer
	set totalData to ""
	repeat numberOfDashes times
		set totalData to "■" & totalData
	end repeat
	return totalData
end if
end

and to round them out, track rating (i don't use this one myself, but it seems to work)

Code:
set notify to ""
property go : false
tell application "System Events"
	set the process_flag to (exists process "iTunes")
end tell
if the process_flag then
	tell application "iTunes"
		if player state is playing then
			set currrate to round (rating of current track) / 20
			set notify to "" & currrate & " stars"
		end if
		if player state is paused then
			set currrate to round (rating of current track) / 20
			set notify to "" & currrate & " stars"
		end if
	end tell
	notify
end if

thanks cerberus 12 for helping with the itunes relaunching issue, hopefully they all work with a straight forward "osascript" shell now.
 
hi everyone!

first of all thanks for the great scripts!


I want to parse an xml file. what I got by now I took from the weatherscripts, but its not perfect.

This is my xml: https://www.rz.fh-hannover.de/etech/schoof/meldungen/export/meldungen.xml

I want to show every <ueberschrift> (german for headline) to show up bold and below that <zeile1> and <zeile2> (line1 and line2).

And each headline with its two lines should be seperated to the next headline with a blank line.

By now, i use this:
Code:
curl https://www.rz.fh-hannover.de/etech/schoof/meldungen/export/meldungen.xml | grep 'ueberschrift' | sed -e 's/<ueberschrift>//g'

to produce this:

Bildschirmfoto%202009-11-01%20um%2012.14.02.png


But I want the headline (<ueberschrift> in bold)

Anyone know how to do this?
Thanks in advance!
 
hi everyone!

first of all thanks for the great scripts!


I want to parse an xml file. what I got by now I took from the weatherscripts, but its not perfect.

This is my xml: https://www.rz.fh-hannover.de/etech/schoof/meldungen/export/meldungen.xml

I want to show every <ueberschrift> (german for headline) to show up bold and below that <zeile1> and <zeile2> (line1 and line2).

And each headline with its two lines should be seperated to the next headline with a blank line.

By now, i use this:
Code:
curl https://www.rz.fh-hannover.de/etech/schoof/meldungen/export/meldungen.xml | grep 'ueberschrift' | sed -e 's/<ueberschrift>//g'

to produce this:

Bildschirmfoto%202009-11-01%20um%2012.14.02.png


But I want the headline (<ueberschrift> in bold)

Anyone know how to do this?
Thanks in advance!
Hi,

let me try and help you here:
- First you should get only the lines you want
Code:
curl https://www.rz.fh-hannover.de/etech/schoof/meldungen/export/meldungen.xml | grep -E '(ueberschrift|zeile)'
This should return only (for example):
<ueberschrift>VDE-Vortrag: 75 Jahre Frequenzumrichter - Eine bersicht</ueberschrift>​
<zeile1>am 20.10.09 um 18:00 Uhr im Hrsaal 100 (Neubau)</zeile1>​
<zeile2>von Prof. Prof. h.c. mult. Dr. Peter F. Brosch</zeile2>​
Then add some leading spaces to the 2nd and 3rd lines:
Code:
curl https://www.rz.fh-hannover.de/etech/schoof/meldungen/export/meldungen.xml | grep -E '(ueberschrift|zeile)' | sed -E 's/\<zeile/  &/1'
Then just remove the xml tags:
Code:
curl https://www.rz.fh-hannover.de/etech/schoof/meldungen/export/meldungen.xml | grep -E '(ueberschrift|zeile)' | sed -E 's/\<zeile/  &/1' | sed -E 's/\<.+>(.+)\<\/.+>/\1/'

And that's it.

Hope it works (they may be some typos - couldn't test it so....)

ps: about the bold part check my other post:
check the codes here
 
Status
Not open for further replies.
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.