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

Posted:
in macOS edited January 2014
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"

\t-- This script extracts information about the track currently running in iTunes, and then

\t-- formats it for one-line display (e.g., using GeekTool).

\t-- See http://www.macosxhints.com/article.p...04070301135736 for a

\t-- detailed description of a similar script that gave me the idea for this one.

\t

\t-- this spacer determines how many spaces are between some of the items in the display:

\tset spacer to " "

\t

\t-- get some simple information and add spaces and punctuation:

\tset myName to name of current track

\tset myArtist to spacer & "< " & artist of current track & " >"

\tset myYear to spacer & "< " & year of current track & " >"

\t

\t-- if the track is in an album, then put a dash before the album name (to separate

\t-- it from the information that will be printed before the album):

\tset myAlbum to album of current track

\tif myAlbum is not "" then

\t\tset myAlbum to spacer & myAlbum

\tend if

\t

\t-- get the current position of the track and calculate how far through

\t-- the track we are, as a percentage:

\tset myPosition to player position

\tset myDuration to duration of current track

\tset myPercent to spacer & (round (myPosition / myDuration * 100)) & "%"

\t

\t-- this final line determines which pieces of information are displayed:

\tset output to myName & myArtist & myAlbum & myYear & myPercent

end tell



thanks



nick

Comments

  • Reply 1 of 1
    putting this one line before the script worked:



    tell application "System Events" to if not (process "iTunes" exists) then return
Sign In or Register to comment.