Resolved Geektool won't let iTunes close while running

Discussion in 'Mac Programming' started by ideal.dreams, Jul 22, 2011.

  1. ideal.dreams, Jul 22, 2011
    Last edited: Aug 1, 2011

    ideal.dreams macrumors 68020

    ideal.dreams

    Joined:
    Jul 19, 2010
    Location:
    OH
    #1
    Hey guys,

    I'm using Geektool to display song information for the current playing song, however, whenever Geektool is running this script it won't allow me to close iTunes. It will quit and reopen right away. In Snow Leopard this hangup wouldn't allow the system to shut down (because SL would close it and it'd open again interrupting the shut down) but would eventually shut down. Now in Lion it won't let me shut down my computer at all because iTunes keeps launching at the last second. Here is the code that I use to display the song information:

    Code:
    #!/bin/sh
    if ps x | grep iTunes | grep -q -v grep;   then 
      osascript -e 'tell application "iTunes"
    set trackname to name of current track
    set artistname to artist of current track
    set albumname to album of current track
    if albumname is null then
    set albumshow to " "
    else if albumname is "" then
    set albumshow to " "
    else 
    set albumshow to "" & albumname & "" 
    end if
    set trackduration to duration of current track
    set trackposition to player position
    set elapsed to round (trackposition / trackduration * 100)
    set myRating to round ((rating of current track) / 20)
    if myRating is 1 then
    set myRating to "* "
    else if myRating is 2 then
    set myRating to "** "
    else if myRating is 3 then
    set myRating to "*** "
    else if myRating is 4 then
    set myRating to "**** "
    else if myRating is 5 then
    set myRating to "***** "
    else
    set myRating to ""
    end if
    set myRating to myRating
    set output to "" & trackname & "\n\n" & artistname  & "\n\n" & albumshow & "\n" & myRating 
      end tell' | iconv -f utf-8 -t ucs-2-internal
    fi
    Can anyone point me to the line that is forcing iTunes to keep reopening?
     
  2. ideal.dreams thread starter macrumors 68020

    ideal.dreams

    Joined:
    Jul 19, 2010
    Location:
    OH
    #2
    The third line is the one that is forcing iTunes to reopen right after I quit the application. Obviously if I remove that line it won't display the song information so can anyone tell me how to modify that line so it will still display information but won't force iTunes to stay open?
     
  3. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #3
    Test at the command prompt.
    myComnand && echo 'True!'

    If you see True! when you want and don't otherwise, you're good.

    Maybe toss a | wc -l
    at the end?

    -Lee
     
  4. chown33, Jul 23, 2011
    Last edited: Jul 23, 2011

    chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    I'm not sure what you mean by "the third line". If you mean "the osascript command", then please say that.


    In this code:
    Code:
    if [COLOR="blue"]ps x | grep iTunes | grep -q -v grep[/COLOR];   then 
      osascript -e 'tell application "iTunes"
    
    the blue-hilited section finds any process whose name or parameters contains "iTunes". Since this will include the 'grep' process itself (the "iTunes" parameter will match), it then filters out any process whose name contains "grep". The likely intended result is to discover if iTunes is running or not, and conditionally perform the subsequent 'osascript' command that tells iTunes what to do. It's probably supposed to only tell iTunes to do something if it's already running. Unfortunately, that isn't what it does.

    What it does is tell iTunes to do something if any process contains the name "iTunes". One such process is iTunesHelper, a faceless helper app that is often running even when iTunes itself isn't running. In fact, most people have it set as a Login Item in their user account. Look in System Preferences > Accounts > Login Items tab.

    I recommend you check the output of this command to see what's running:
    Code:
    ps x | grep iTunes
    
    This command in Terminal will terminate iTunesHelper:
    Code:
    killall iTunesHelper
    
    Copy and paste it exactly, because it's case-sensitive.

    Next, if you didn't write that script, file a bug-report with whoever did write it and tell them they need to fix it. If they want to know what the problem is, give them the URL of this thread:
    http://forums.macrumors.com/showthread.php?t=1195305
     
  5. ideal.dreams, Jul 23, 2011
    Last edited by a moderator: Jul 23, 2011

    ideal.dreams thread starter macrumors 68020

    ideal.dreams

    Joined:
    Jul 19, 2010
    Location:
    OH
    #5
    Thanks for the help, I'm sorry I wasn't more specific about the command that was causing it. iTunesHelper is not running and iTunes still will not close without reopening right away.
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #6
    Then it's likely something else is running that has the word "iTunes" in its command name or a parameter.

    The way to find out what else is running is this command:
    Please copy and paste that into a Terminal window, then copy and paste the resulting output into a reply post. Post the entire output; I expect to see the 'grep' process itself.


    Also, did you write that script, or did someone else?

    p.s. You don't have to quote my posts if it's clear your replying to what I just posted.
     
  7. ideal.dreams thread starter macrumors 68020

    ideal.dreams

    Joined:
    Jul 19, 2010
    Location:
    OH
    #7
    Here is the output of the command.

    Code:
    Adams-MacBook-Pro:~ **********$ ps -x | grep iTunes
    23807 ??         2:39.62 /Applications/iTunes.app/Contents/MacOS/iTunes -psn_0_823497
    23808 ??         0:00.18 /Applications/Bowtie.app/Contents/Resources/Bowtie Butler /Applications/Bowtie.app/Contents/Butlers/iTunes.btbutler com.13bold.Butler.iTunes.Local 275
    49208 ttys000    0:00.00 grep iTunes
    I didn't write the script, I found it online.
     
  8. chown33, Jul 24, 2011
    Last edited: Jul 24, 2011

    chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #8
    Bowtie.app is running, and is using the file /Applications/Bowtie.app/Contents/Butlers/iTunes.btbutler . The presence of the pattern iTunes in that file is causing a false positive for the 'if' command. In short, it thinks iTunes is running, so it tells it things to do. Since iTunes isn't running, it gets launched.

    Here's a replacement to try.

    Replace this line in your original script:
    Code:
    if ps x | grep iTunes | grep -q -v grep;   then 
    
    with the following:
    Code:
    if ps -x -o command \
     | grep '^/Applications/iTunes.app/' \
     | grep -q -v 'iTunesHelper';  then
    
    Copy and paste the new lines exactly as given.

    If it works, then it should continue working until something significant changes about iTunes internals, or its location in the Applications folder.

    If it doesn't work, post again and I'll give a different pattern that should work.

    The original code simply looked for any process whose command or parameter contained "iTunes", then excluded the inevitable 'grep' command. This is prone to false positives, and is a guaranteed failure if iTunesHelper is active (as it normally is).

    The new code specifically looks for a process running from "/Applications/iTunes.app/", then excludes iTunesHelper, which is the only other process that should ever be running with that prefix. The reason iTunesHelper's command name starts with that pattern is because it's actually a subsidiary app embedded within the iTunes app itself.
     
  9. ideal.dreams thread starter macrumors 68020

    ideal.dreams

    Joined:
    Jul 19, 2010
    Location:
    OH
  10. dissonance42 macrumors newbie

    Joined:
    Aug 21, 2008
    #10
    So, I've got the same problem going right now. I do not have the Bowtie issue, but I do have the "GeekTools won't let iTunes stay closed" issue.

    My end goal here is just to get iTunes lyrics to show on the desktop through GeekTools. I found a script online that will do this that is similar to the one above:

    osascript -e '''tell application "/Applications/iTunes.app/" to set currentLyrics to the lyrics of the current track'''

    But when using this script, I run into the same issue where iTunes will not stay closed. I made an attempt at modifying the scripts that you suggested to fit my needs:

    #!/bin/sh
    if ps -x -o command \
    | grep '/Applications/iTunes.app/' \
    | grep -q -v 'iTunesHelper'; then
    osascript -e '''tell application "/Applications/iTunes.app/" to set currentLyrics to the lyrics of the current track'''
    end tell' | iconv -f utf-8 -t ucs-2-internal

    But this doesn't fly with GeekTools for some odd reason, and once this script is set, the refresh kills the desktop lyrics.

    Could I politely ask for some assistance? I'm not the best with scripting, so This is all just one big learning experience for me. :rolleyes:
     

Share This Page