1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Applescript Help

Discussion in 'Mac Programming' started by veditor78, May 25, 2011.

  1. veditor78, May 25, 2011
    Last edited by a moderator: May 26, 2011

    macrumors newbie

    #1
    I am in need of some help modifying some existing Applescript. I am trying to write a script that will go through all the lyrics in my iTunes library and create a playlist of songs that have explicit lyrics. I got Doug Adam's "No Lyrics to Playlist" scripts and tried to modify it.

    It works if it looks for only one word. I can't figure out how to get it to look for a list of possible words, any of which would add the song to the playlist.

    I have tried the following:

    1. Adding a variable and giving it a string - {"*****", "*****", "p*ssy'} - but without the astriks, obviously.

    2. Putting the string right in the "if" statement.

    3. Listing the words in the "if" statement separated by "or".

    All fail to produce a single song in the playlist.

    Here is the script that is working now (only one word searched for).

    __________________________________________________________

    Code:
    property my_title : "Explicit Lyrics to Playlist"
    
    -- you can change the name of the "Explicit Lyrics" playlist here:
    property playlistName : "Explicit Lyrics"
    -- but make sure you change it in "Clean No Lyrics Paylist", too.
    
    tell application "iTunes"
    	set musicLibrary to (get view of front browser window)
    	set musicLibraryName to (get name of musicLibrary)
    	display dialog "This script will create playlist \"" & playlistName & "\", search \"" & musicLibraryName & "\" for songs with explicit lyrics and add them to the \"" & playlistName & "\" playlist." buttons {"Cancel", "OK"} default button 1 with title my_title
    	if (not (exists playlist playlistName)) then
    		set new_playlist to make new playlist with properties {name:playlistName}
    	else
    		set new_playlist to playlist playlistName
    	end if
    	repeat with t from 1 to (index of last track of musicLibrary)
    		try
    			with timeout of 30 seconds
    				set aTrack to (track t of musicLibrary)
    				try
    					set lyr to (get lyrics of aTrack)
    					set dbid to (get database ID of aTrack)
    					if lyr contains "*****" and not (exists (some track of new_playlist whose database ID is dbid)) then duplicate aTrack to new_playlist
    				end try
    			end timeout
    		end try
    	end repeat
    	--	beep
    	display dialog "Done creating playlist \"" & playlistName & "\"." buttons {"OK"} default button 1
    end tell
    __________________________________________________________

    I am far from a programmer and I would really appreciate any help I can get. Thanks in advance!
     
  2. macrumors regular

    #2
    There is undoubtedly a way to loop through an array in applescript, but as I dont know applescript I can't help immediately with that soltuion. However, as a quick and dirty soultion, just add multiple if statements, one for each word.

    Code:
    if lyr contains "word1" and not (exists (some track of new_playlist whose database ID is dbid)) then duplicate aTrack to new_playlist
    if lyr contains "word2" and not (exists (some track of new_playlist whose database ID is dbid)) then duplicate aTrack to new_playlist
    if lyr contains "word3" and not (exists (some track of new_playlist whose database ID is dbid)) then duplicate aTrack to new_playlist
     

Share This Page