unicode text problen

hey,hey and hello,

I ran into a problem which is the following:

error "«class cfol» \"Macintosh HD:Users:XXX:Desktop:test:+44:Lance Armstrong_ Run Longer\" of application \"Finder\" kann nicht in Typ Unicode text umgewandelt werden." number -1700 from «class cfol» "Macintosh HD:Users:XXX:Desktop:test:+44:Lance Armstrong_ Run Longer" to Unicode text

the part +44 is created as a folder and within this folder another one (Lance Armstrong: Run Longer) should be created. I managed it to replace the “:” with “_” like it does iTunes. but than the error occurs… i’m not seeing the error…

btw. below you’ll find the replace scpt and the move scpt both are run in one large scpt.

on findAndReplace(tofind, toreplace, TheString)
	set ditd to text item delimiters
	set text item delimiters to tofind
	set textItems to text items of TheString
	set text item delimiters to toreplace
	if (class of TheString is string) then
		set res to textItems as string
	else -- if (class of TheString is Unicode text) then
		set res to textItems as Unicode text
	end if
	set text item delimiters to ditd
	return res
end findAndReplace
to move_it(file_path, internal_drive, art, alb)
	set artistFolder to art as Unicode text
	
	set albumFolder to get findAndReplace(":", "_", alb) as Unicode text
	set l_folder to internal_drive as Unicode text
	
	--check if artist & album folder exists
	tell application "Finder"
		if not (folder (l_folder & artistFolder) exists) then
			make new folder at l_folder with properties {name:artistFolder} --create artist folder
			if not (folder (l_folder & artistFolder & albumFolder) exists) then
				make new folder at l_folder & artistFolder with properties {name:albumFolder} --create album folder
			end if
		end if
		
		set the finalPath to folder (l_folder & artistFolder & ":" & albumFolder) as Unicode text
		
		try
			duplicate file file_path to folder finalPath with replacing --copy files to album folder
		on error eM number eN
			display dialog "Error " & eN & return & eM with icon 2
		end try
	end tell
end move_it

thanks very much for any hint :slight_smile:

Hi,

is your script supposed to run on system versions prior to Leopard?
If not you can omit the distinction string / Unicode text.
Since Leopard there is a unique text class in AppleScript called text.

You should always add the specifier keywords item, file or folder in front of a string path
while dealing with Finder items in a Finder tell block.

The location property in iTunes contains an alias specifier therefore omit the keyword file before file_path


on findAndReplace(tofind, toreplace, TheString)
	set ditd to text item delimiters
	set text item delimiters to tofind
	set textItems to text items of TheString
	set text item delimiters to toreplace
	set res to textItems as text
	set text item delimiters to ditd
	return res
end findAndReplace



to move_it(file_path, internal_drive, art, alb)
	set artistFolder to art -- as Unicode text
	
	set albumFolder to get findAndReplace(":", "_", alb) -- as Unicode text
	set l_folder to internal_drive as text
	
	--check if artist & album folder exists
	tell application "Finder"
		if not (exists folder (l_folder & artistFolder)) then
			make new folder at folder l_folder with properties {name:artistFolder} --create artist folder
			if not (exists folder (l_folder & artistFolder & ":" & albumFolder)) then
				make new folder at folder (l_folder & artistFolder) with properties {name:albumFolder} --create album folder
			end if
		end if
		
		set the finalPath to folder (l_folder & artistFolder & ":" & albumFolder)
		
		try
			duplicate file_path to finalPath with replacing --copy files to album folder
		on error eM number eN
			display dialog "Error " & eN & return & eM with icon 2
		end try
	end tell
end move_it


Hey stefan,

thx so far!! but now at the following part there is trouble…

set the finalPath to folder (l_folder & artistFolder & ":" & albumFolder)

it says


tell application "Finder"
	exists folder "Macintosh HD:Users:XXX:Desktop:test:+44"
		--> true
	get folder "Macintosh HD:Users:XXX:Desktop:test:+44:Lance Armstrong_ Run Longer:"
		--> error number -1728 from folder "Macintosh HD:Users:goeste:Desktop:test:+44:Lance Armstrong_ Run Longer:"
Ergebnis:
error "žFinder" hat einen Fehler erhalten: žfolder \"Macintosh HD:Users:XXX:Desktop:test:+44:Lance Armstrong_ Run Longer:\"" kann nicht gelesen werden." number -1728 from folder "Macintosh HD:Users:XXX:Desktop:test:+44:Lance Armstrong_ Run Longer:"

the ‘Lance Armstrong’ folder is not being created…

if the folder +44 exists the part to create the sub folder will never be called.
Use this


.
if not (exists folder (l_folder & artistFolder)) then
	make new folder at folder l_folder with properties {name:artistFolder} --create artist folder
end if
if not (exists folder (l_folder & artistFolder & ":" & albumFolder)) then
	make new folder at folder (l_folder & artistFolder) with properties {name:albumFolder} --create album folder
end if
.

now… a loop within a loop… true calling stefan, thx for the wakeup call :wink:

no i will go ahead with my iunes project :wink: http://macscripter.net/viewtopic.php?id=10229

thx k-times