"if (exists folder...)" statement not working right

I’ve combined Doug Adam’s “Lyrics to TextEdit” iTunes script with Apple’s own “Clipboard to iPod Note” script to make a script that takes the currently playing or selected song[s] in iTunes and copies the Lyrics of the song[s] to a note on my iPod (sure wish Apple would include the nano’s lyrics-viewing feature in an update to non-nano iPods).
There is a “Lyrics” folder within the “Notes” folder of my iPod where I’m trying to save the notes to. If I leave the script set up to simply save the note[s] into the “Lyrics” folder, it works like a champ, but that’s not good enough for me–I want the script to check for a subfolder of the “Lyrics” folder named for the artist of the track being operated on, and if it exists, save the track’s lyrics to that folder (e.g. :My iPod:Notes:Lyrics:ArtistName:). If a folder named for the artist doesn’t exist, I want the script to create one, and then save the file there.
The problem I’m having is this: If multiple tracks by the same artist are selected, it will run through to completion once, successfully creating the artist folder, and saving the lyrics note. But on the iteration for the second track, the if (exists (folder whose name is …)) generates an error saying that the folder already exists. In other words, I have an if statement checking to see if the artist folder exists–if so, move on to saving the note in that folder; if not, create the folder, then move on to saving the note in that folder. But for some reason, wether or not the folder exists, the else statement that creates the new folder is being executed even if the folder already exists.
Here’s my script, with the broken part commented:


Can anyone tell me how to fix the Finder tell statement here so that it works the way it should? I have a feeling it has something to do with how my entities and classes are being identified, but I’m strictly an AS amateur, so I don’t know enough to fix this.
TIA!

Browser: Firefox 1.0.7
Operating System: Mac OS X (10.4)

My guess is that whose is the problem?

Works…
if exists folder “Users” of disk “Macintosh HD” then

Doesn’t work…
if exists (folder whose name is “Users”) of disk “Macintosh HD” then

Someone smarter than me will have to explain why.

or…

set theArtistFolderPath2Test to (this_iPod as string) & “:notes:Lyrics:” & artist_folder
if exists theArtistFolderPath2Test then

p.s. … You’re well past amature status.

Thanks for the reply. I tried what you said, but it didn’t work. Still get the same error. It’s still executing the “else” statement which tries to create the new folder, even when it already exists.
FWIW, here’s the output of the event log when I run it in Script Editor:

tell application "Finder"
	exists "My iPod::Notes:Lyrics:Metallica"
		false
	make new folder with properties {name:"Metallica"} at folder "Lyrics" of folder "Notes" of alias "My iPod:"
		"Finder got an error: The operation could not be completed because there is already an item with that name."

For some reason, it’s not seeing the existing folder. You can see in the Event Log that the “if exists” statement is returning false, which clearly, in my case, isn’t right after the first iteration. Very odd.

Here are some more suggestions to try:

Try building the paths before you get to the if/then/else section to cut down on translation work. For instance, instead of a run of folder of, folder of, etc., build the folder name and assign it to a variable:

set l_folder to this_pod & "Notes:"&"Lyrics:"& artist_folder as unicode text

Now, you have the exact name and location of the folder you want to test for as a variable.

I have had similar issues with these folder tests before, and sometimes I will test for the folder NOT existing:

set mainpath to path to desktop as Unicode text
set need_fold to "WhateverYouWant"
tell application "Finder"
	if not (folder (mainpath & need_fold) exists) then
		make new folder at mainpath with properties {name:need_fold}
	end if
end tell

This is a script snippet I use in my stuff a lot.

Good luck, keep at it; it will work eventually.

casdvm

casdvm,
Thanks, that worked like a champ!
I just replaced the explicit folder references with the reference variable, and all is well!
Thanks to all for your help!
In case anyone is interestd, here’s my working script that takes the lyrics of the playing/selected track[s] in iTunes, and transfers them to a folder in my iPod named for the artist of the track. The artist folders are in a subfolder of the Notes folder called Lyrics. The script checks to see if the artist folder exists, and if not, it creates it. If no iPod is connected, it returns a warning.


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]