property plOld : "@@old@@"

global iTunesRunning, iTunesRunning, existsCurrent, ok_to_Idle

on run
	set ok_to_Idle to false
	set iTunesRunning to false
	set e to my running_apps()
	if e contains "iTunes" then
		set iTunesRunning to true
		tell me to purge_old()
	end if
end run

on purge_old()
		tell application "System Events"
			set iTunesRunning to (exists process "iTunes")
		end tell
		if iTunesRunning then
			tell application "iTunes"
				repeat with everyTrack in every track of playlist plOld
					if everyTrack's rating < 20 then
						set everyTrack's rating to 0
						set old to everyTrack's rating
						set everyTrack's rating to old - 20
					end if
				end repeat
			end tell
		end if
	end try
end purge_old

on running_apps()
	tell application "System Events"
		return (get name of every process)
	end tell
end running_apps