need help to amend a script so that it only runs if iTunes is running

Discussion in 'macOS' started by nick_harambee, Jul 20, 2009.

  1. nick_harambee macrumors regular

    Joined:
    May 20, 2005
    #1
    hi

    i have been using a script developed by someone else and posted online which uses geektool in combination with a script to display information about the currently playing track in iTunes in the menu bar. everything works fine, but there is one problem, namely that in order to get accurate information from iTunes (including the percentage of the track that has been played), i have set the refresh rate to 1 second, which means that each time I try to restart my Mac I have to disable geektool before I can do so, because if I don't geektool will relaunch iTunes one second after it has quit, and this cancels the restart.

    I would like to not have to disable and then enable geektool each time i restart my mac, and wonder if there is anything I can do, such as amending the script to only run if iTunes is running, so that I don't have to do disable/enable geektool. I have very little experience with scripting. Here is the script I am currently running:

    tell application "iTunes"
    -- This script extracts information about the track currently running in iTunes, and then
    -- formats it for one-line display (e.g., using GeekTool).
    -- See http://www.macosxhints.com/article.php?story=2004070301135736 for a
    -- detailed description of a similar script that gave me the idea for this one.

    -- this spacer determines how many spaces are between some of the items in the display:
    set spacer to " "

    -- get some simple information and add spaces and punctuation:
    set myName to name of current track
    set myArtist to spacer & "< " & artist of current track & " >"
    set myYear to spacer & "< " & year of current track & " >"

    -- if the track is in an album, then put a dash before the album name (to separate
    -- it from the information that will be printed before the album):
    set myAlbum to album of current track
    if myAlbum is not "" then
    set myAlbum to spacer & myAlbum
    end if

    -- get the current position of the track and calculate how far through
    -- the track we are, as a percentage:
    set myPosition to player position
    set myDuration to duration of current track
    set myPercent to spacer & (round (myPosition / myDuration * 100)) & "%"

    -- this final line determines which pieces of information are displayed:
    set output to myName & myArtist & myAlbum & myYear & myPercent
    end tell

    thanks

    nick
     
  2. nick_harambee thread starter macrumors regular

    Joined:
    May 20, 2005
    #2
    putting this one line before the script worked:

    tell application "System Events" to if not (process "iTunes" exists) then return
     

Share This Page