Go Back   MacRumors Forums > Mac Community > Picture Gallery > UI Customization

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 31, 2013, 10:02 PM   #1
bpark919
macrumors newbie
 
Join Date: Jan 2013
Cool If you can fix this Geektool/Applescript quandary...

Hello! I just discovered Geektool last night and have been going crazy with all the options. I found a really cool geeklet that displays the itunes song rating, but right now it only displays the number of stars in the rating. I figured out how to display 5 "white" stars when it has no rating, but my attempts to always display 5 stars is failing. Here is the script I came up with so far...


#!/usr/bin/osascript

on run
set info to ""
tell application "System Events"
set num to count (every process whose name is "iTunes")
end tell
if num > 0 then
tell application "iTunes"
set how to rating of current track
if how is 0 then return "☆☆☆☆☆"
if how is 1 then return "★☆☆☆☆"
if how is 2 then return "★★☆☆☆"
if how is 3 then return "★★★☆☆"
if how is 4 then return "★★★★☆"
if how is 5 then return "★★★★★"
set how to how / 20 as integer
set star to {"★"}
set infoitems to {}
set starnum to 0
repeat
set infoitems to infoitems & star
set starnum to starnum + 1
if starnum = how then exit repeat
end repeat
set info to infoitems as string
end tell
end if
return info
end run

I totally added all the "if how is" 1-5; if how is 0 works but all the other ones only display the number of stars in the rating.

Any help would be much appreciated, thank you![COLOR="#808080"]

----------

All I had to do was move the "if how is" 1-5 until AFTER I set how.

This is the new code, for anyone that wants to use this updated one...


#!/usr/bin/osascript

on run
set info to ""
tell application "System Events"
set num to count (every process whose name is "iTunes")
end tell
if num > 0 then
tell application "iTunes"
set how to rating of current track
if how is 0 then return "☆☆☆☆☆"

set how to how / 20 as integer
if how is 1 then return "★☆☆☆☆"
if how is 2 then return "★★☆☆☆"
if how is 3 then return "★★★☆☆"
if how is 4 then return "★★★★☆"
if how is 5 then return "★★★★★"
set star to {"★"}
set infoitems to {}
set starnum to 0
repeat
set infoitems to infoitems & star
set starnum to starnum + 1
if starnum = how then exit repeat
end repeat
set info to infoitems as string
end tell
end if
return info
end run

GEEKTOOL IS AMAZING, I haven't done anything else in the past day!!!!! Will post my desktop once I get it perfect. HAHA!
bpark919 is offline   0 Reply With Quote
Old Jan 31, 2013, 10:04 PM   #2
Intell
macrumors P6
 
Intell's Avatar
 
Join Date: Jan 2010
Location: Inside
Give this a try:

Code:
tell application "System Events" to set allAppList to name of application processes
if allAppList contains "iTunes" then
	tell application "iTunes"
		set trackRating to rating of current track
		if trackRating is 0 then
			set returnStart to "☆☆☆☆☆"
		else if trackRating is 1 then
			set returnStart to "★☆☆☆☆"
		else if trackRating is 2 then
			set returnStart to "★★☆☆☆"
		else if trackRating is 3 then
			set returnStart to "★★★☆☆"
		else if trackRating is 4 then
			set returnStart to "★★★★☆"
		else if trackRating is 5 then
			set returnStart to "★★★★★"
		else
			set returnStart to "ERROR"
		end if
	end tell
	return returnStart
end if
__________________
Last edited by Intell; Yesterday at 3:16 AM.
Intell is offline   0 Reply With Quote
Old Jan 31, 2013, 10:07 PM   #3
bpark919
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
Intell, thanks for the quick reply!

I posted my own reply because I figured it out right after I posted it, or at least I got it to work...

----------

#!/usr/bin/osascript

on run
set info to ""
tell application "System Events"
set num to count (every process whose name is "iTunes")
end tell
if num > 0 then
tell application "iTunes"
set how to rating of current track
if how is 0 then return "☆☆☆☆☆"

set how to how / 20 as integer
if how is 1 then return "★☆☆☆☆"
if how is 2 then return "★★☆☆☆"
if how is 3 then return "★★★☆☆"
if how is 4 then return "★★★★☆"
if how is 5 then return "★★★★★"
set star to {"★"}
set infoitems to {}
set starnum to 0
repeat
set infoitems to infoitems & star
set starnum to starnum + 1
if starnum = how then exit repeat
end repeat
set info to infoitems as string
end tell
end if
return info
end run


It's definitely nowhere near as sophisticated, but it seems to work. Would it cause any problems or anything? I honestly know nothing about coding, I'm figuring out how to "tweak" scripts using common sense and guess and check! xP
bpark919 is offline   0 Reply With Quote
Old Jan 31, 2013, 10:10 PM   #4
Intell
macrumors P6
 
Intell's Avatar
 
Join Date: Jan 2010
Location: Inside
Your script seems to have some unneeded counting and logic in it. They should both get the end result of having the stars printed. I don't see any problems with it at all.
__________________
Last edited by Intell; Yesterday at 3:16 AM.
Intell is offline   0 Reply With Quote
Old Jan 31, 2013, 10:15 PM   #5
bpark919
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
Question

Thanks! I was also wondering if you could help me out with a problem with my dateline calendar.

Here's the code:

Code:
#!/usr/bin/env ruby
#
# Author: Robert Jorgenson
# Author email: rjorgenson@gmail.com
require 'Date'
ABBR_DAYNAMES = {0, 'Su', 1, 'Mo', 2, 'Tu', 3, 'We', 4, 'Th', 5, 'Fr', 6, 'Sa'}

def days_in_month(year, month)
  return (Date.new(year, 12, 31) << (12 - month)).day
end

def day_in_month(year, month, day)
  return Date.new(year, month, day).wday
end

def build_day_array(year, month)
  day_array = Array.new
  for d in (1..days_in_month(year, month))
    day_array[d] = ABBR_DAYNAMES[day_in_month(year, month, d)]
  end
  day_array.shift
  return day_array * "   "
end

def build_separator(year, month)
  red = "\e[31m" #uncomment for red
black = "\e[30m"
  separator_string = "[]" # change this to change separator, best if 2 characters wide
  close = "\e[30m" # don't change this
  separator = Array.new
  for d in (1..days_in_month(year, month))
    if year == Time.now.year && month == Time.now.month && d == Time.now.day then
      separator[d] = "#{red}#{separator_string}#{close}"
    else
      separator[d] = "#{black}#{separator_string}"
    end
  end
  separator.shift
  return separator * "   "
end

def build_date_array(year, month)
  date_array = Array.new
  for d in (1..days_in_month(year, month))
    date_array[d] = d
  end
  date_array.shift
  date_array.each do |d|
    if d < 10 then
      date_array[(d-1)] = "0#{d}"
    end
  end
  return date_array * "   "
end

year = Time.now.year
month = Time.now.month

puts build_day_array(year, month)
puts build_separator(year, month)
puts build_date_array(year, month)
It originally displayed everything in white, with only the separator being green. I figured out how to turn the date and the separators black, with the separator of the current day in red. However, the days of the week (on top) are still white; I couldn't figure it out so I gave up but maybe you could shed some light? I hope for my end product to display everything in black except the current day, date, and separator in red.

Also, my girlfriend pointed out (I hadn't noticed it before) that the calendar is enclosed in a dark grey box... is there any way to make that transparent?

Thank you so much!
bpark919 is offline   0 Reply With Quote
Old Jan 31, 2013, 10:49 PM   #6
Intell
macrumors P6
 
Intell's Avatar
 
Join Date: Jan 2010
Location: Inside
I'll be able to help you some time tomorrow. But for now, it's bed time.
__________________
Last edited by Intell; Yesterday at 3:16 AM.
Intell is offline   0 Reply With Quote


Reply
MacRumors Forums > Mac Community > Picture Gallery > UI Customization

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Geektool Dateline Fix crystalblu OS X Mavericks (10.9) 1 Jun 16, 2014 12:49 PM
Geektool: GeekTool's Applescript Capabilities BenJuan26 UI Customization 4 Sep 19, 2013 02:29 PM
Time Capsule quandary meistervu Mac Peripherals 14 Jun 14, 2013 12:06 PM
Geektool: Applescript for Geektool Communicator UI Customization 0 Mar 12, 2013 08:19 AM
My Quandary on MBP and MBA theDH Buying Tips and Advice 0 Jun 13, 2012 09:52 AM

Forum Jump

All times are GMT -5. The time now is 09:49 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC