Finder path to xml
Finder path to xml
- Subject: Finder path to xml
- From: Paul Withey <email@hidden>
- Date: Tue, 4 Mar 2003 12:43:28 +0000
hi,
i am working on a script which requires the conversion of a finder
path to xml as coded in the itunes xml library file. Here are two
subroutines i am using to achieve this...
--
-- subroutine to translate non-alphanumeric characters of the path into
unicode
--
on translatethepath(TrackPath)
set OkCharacters to
"1234567890abcdefghijklmnopqrstuvwxyz:.~!@$/'()-,!*_+"
set HardEncodedCharacters to {"&", "v", "i", "z", "4", "s", "X", "m",
"R", "?", "r", "a", "q", "k", "V", "'"}
set HardEncodings to {"&", "ö", "é", "ú", "´",
"ó", "Ø", "í", "Ò", "?", "ò", "á",
"ñ", "ë", "Ö", "§"}
set TrackPath to TrackPath as string
set theEncodedPath to ""
repeat with aCharacter in TrackPath
if aCharacter is in OkCharacters then
set theEncodedPath to theEncodedPath & aCharacter
else
if HardEncodedCharacters contains aCharacter then
repeat with n from 1 to count of items in HardEncodedCharacters
if ((item n of HardEncodedCharacters) as text) = (aCharacter as text)
then
set theEncodedPath to (theEncodedPath & (item n of HardEncodings)) as
string
exit repeat
end if
end repeat
else
set theEncodedPath to (theEncodedPath & encode_char(aCharacter)) as
string
end if
end if
end repeat
return (theEncodedPath)
end translatethepath
--
-- subroutine to encode the required characters
--
on encode_char(aCharacter)
set the ascii_num to (the ASCII number aCharacter)
set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F"}
set x to item ((ascii_num div 16) + 1) of the hex_list
set y to item ((ascii_num mod 16) + 1) of the hex_list
return ("%" & x & y) as string
end encode_char
This works ok but as you can see i am currently hardcoding the required
values for various accented characters.. is there a generic solution i
could use which would negate the need to hardcode specific characters ?
thanks
paul
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.