Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 25, 2011, 09:34 PM   #1
veditor78
macrumors newbie
 
Join Date: Aug 2010
Location: St. Charles, MO
Applescript Help

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!

Last edited by kainjow; May 26, 2011 at 03:12 AM. Reason: code tags
veditor78 is offline   0 Reply With Quote
Old May 26, 2011, 07:56 AM   #2
MasConejos
macrumors regular
 
Join Date: Jun 2007
Location: Houston, TX
Send a message via ICQ to MasConejos
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
MasConejos is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Why so much Applescript? Dranix Mac Programming 25 May 2, 2014 02:05 AM
help with applescript andrewisgod Mac Programming 0 Apr 18, 2014 08:58 AM
AppleScript: How do I save multiple Excel sheets to one pdf using Applescript sbtaylor1 Mac Programming 0 Oct 29, 2013 12:38 AM
AppleScript: How do I save multiple Excel sheets to one pdf using Applescript sbtaylor1 Mac Applications and Mac App Store 0 Oct 29, 2013 12:32 AM
Help with an Applescript Theydonboi Mac Applications and Mac App Store 2 Nov 5, 2012 12:52 PM

Forum Jump

All times are GMT -5. The time now is 11:49 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC