Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 25, 2011, 08: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 02:12 AM. Reason: code tags
veditor78 is offline   0 Reply With Quote
Old May 26, 2011, 06: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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Handling Duplicate AppleScripts the Otter Mac Programming 1 Dec 22, 2010 05:53 AM
Applescript NOOB Revolume Mac Programming 2 Dec 1, 2010 08:06 AM
help with excel for mac 2008 damiang72 Mac Applications and Mac App Store 0 Nov 14, 2010 06:19 AM
AppleScript Help krohde Mac Help/Tips 2 Mar 20, 2003 05:06 PM
AppleScript help cleo General Mac Discussion 0 Apr 10, 2002 08:21 PM


All times are GMT -5. The time now is 04:31 PM.

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

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