Making Symbolic Links - What's wrong with my script?

Hi everybody, I’m hitting a weird snag with a script I made. I’m a total newbie, so this took me quite a while to put together. Look below the script for more info on what I’m trying and why, but the gist is that I’m creating symbolic links for a set of files. I’m running a shell script to do it. The script appears to run fine, no errors or anything. But there are no links when it’s done. And attempting to run it again gives me this error:

error “ln: Mac Server:Users:Maddux:Movies:Boxee Videos:TV Shows:Arrested.Development.(2003).S01E01.Pilot.mkv: File exists” number 1

But there is definitely no file by that name in that folder. Not sure what’s going on.

(Note: sorry for the over-commenting in the script. Like I said, I’m a little green so I mostly did it to keep it all straight while I’m working on it.)


--sub-routine for character replacement in string
on replace_chars(this_text, search_string, replacement_string)
	set AppleScript's text item delimiters to the search_string
	set the item_list to every text item of this_text
	set AppleScript's text item delimiters to the replacement_string
	set this_text to the item_list as string
	set AppleScript's text item delimiters to ""
	return this_text
end replace_chars

--sub-routine for creating symbolic link for given file
on createSymbLink(currentEpisode, charToRemove, symbLinkFolder)
	set newFileName to currentEpisode as string
	set newFileName to text (charToRemove + 1) thru end of newFileName
	set newFileName to my replace_chars(newFileName, "Season ", "S")
	set newFileName to my replace_chars(newFileName, ":0", "E0")
	set newFileName to my replace_chars(newFileName, ":1", "E1")
	set newFileName to my replace_chars(newFileName, ":2", "E2")
	set newFileName to my replace_chars(newFileName, " ", ".")
	set newFileName to my replace_chars(newFileName, ":", ".")
	do shell script "ln -s " & quoted form of currentEpisode & " " & quoted form of (symbLinkFolder & newFileName) password "*****" with administrator privileges
end createSymbLink


on run
	--locate original files
	set tvFolder to (choose folder with prompt "Select where your TV shows are held.") as string
	--choose where to store symbolic links
	set symbLinkFolder to (choose folder with prompt "Choose where to store your symbolic links.") as string
	--determine how many characters to remove from path for creating symbolic link
	set charToRemove to number of characters of tvFolder
	
	tell application "Finder"
		--get shows in TV Shows folder
		set showList to every folder of folder tvFolder
		--declare show loop index
		set showInd to 1
		--cycle through each show
		repeat the count of showList times
			--select the current show based on show index
			set currentShow to item showInd of showList as string
			--get seasons of current show
			set seasonList to every folder of folder currentShow
			--declare season loop index
			set seasonInd to 1
			--cycle through each season
			repeat the count of seasonList times
				--select current season based on season index
				set currentSeason to item seasonInd of seasonList as string
				--get episodes of current season
				set episodeList to every file of folder currentSeason
				--declare episode loop index
				set episodeInd to 1
				--cycle through each episode
				repeat the count of episodeList times
					--select current episode based on episode index
					set currentEpisode to item episodeInd of episodeList as string
					--create symbolic link for current episode
					my createSymbLink(currentEpisode, charToRemove, symbLinkFolder)
					--select next episode
					set episodeInd to episodeInd + 1
				end repeat
				--select next season
				set seasonInd to seasonInd + 1
			end repeat
			--select next show
			set showInd to showInd + 1
		end repeat
	end tell
end run

For those who want to know what the heck I’m doing:
I’m wanting to create symbolic links for each file in my video collection. I have a Boxee Box and it wants the filenames in a very specific format (Show.Name.(Year).S##E##.Episode.Name.ext) but I find that totally hard to read on my other clients (Tivo, iOS Devices, etc) so I like to keep my files organized more simply (Show Name (Year)/Season ##/## Episode Name.ext). It’s not a big deal but I thought it might be some good scripting practice. After some searching and finding that character replacement subroutine and a basic shell for my loop I thought I had everything figured out. Everything works fine and it spits out the right filenames, but no file afterwards. But running it again seems to hint that there IS a file there.

Anyway, if anybody’s got time to check it out I’d be much appreciated.

Hi,

the shell expects POSIX paths (slash separated), you pass a HFS path (colon separated).
Try this


.
set symbLinkFolder to POSIX path of (choose folder with prompt "Choose where to store your symbolic links.")
.

Aha, I think that’s it! Since it didn’t see it as a path, I’m actually finding now that it was creating the files at the root of the drive with crazy long filenames. I can’t experiment now, but that has to be the fix!

Thanks!