can't write decomposedstring to file

Hi All,

I have a text file that rsync reads for excluded items.

I just discovered that accented characters are not seen so “théôldpath” won’t work in a path name.

so I used this to get the decomposed string:

tell class "NSString" of current application
		set excludeList to inputExcludeLines's decomposedStringWithCanonicalMapping()
end tell

I was using the applescipt “open for access” and write command but this doesn’t work with the decomposed string. It decomposes the line breaks and everything.

I initially used do shell script “echo excludeList filePath” which works well. Unfortunately there were issues with using echo (which I can’t remember at the moment) so I am now trying writeToFile:

tell class "NSString" of current application
excludeList's  writeToFile_atomically_(filePath, true)
end tell

This writes but doesn’t retain the decomposed string so the accents throw things off again.

I tried doing it with the encoding but can’t get this to work at all:

tell class "NSString" of current application
excludeList's  writeToFile_atomically_encoding_error_(filePath, true, "NSUTF8StringEncoding", null)
end tell

Anyone have an idea how to write the decomposed string to file?

Thanks, Rob

tell class "NSString" of current application
excludeList's writeToFile_atomically_encoding_error_(filePath, true, "NSUTF8StringEncoding", null)
end tell

writeToFile_atomically_encoding_error_ is an instance method, so you shouldn’t be sending that message to the class. It should be:

 excludeList's writeToFile_atomically_encoding_error_(filePath, true, current application's NSUTF8StringEncoding, missing value)

If I put text that has foreign characters in excludedList, this writes them fine. I’m not sure what you meant by “This writes but doesn’t retain the decomposed string so the accents throw things off again”. I’ve never used rsync so I don’t know if this gets to the heart of your problem.

Ric

Yes Ric,

That works.I forgot about addressing the NSUTF8StringEncoding correctly. The string does need to be decomposed first, otherwise the accents aren’t read by the rsync exclude function.

Thanks so much and Happy Holidays, Rob

Rob,

FYI, the issue you’re dealing with really has nothing to do with decomposition – it’s purely an encoding issue.

Hi Shane,

So far I can’t seem to get this to work without the decomposing;

tell class "NSString" of current application
	set newstring to stringWithString_(excludeList)
	excludeList's writeToFile_atomically_encoding_error_(excludetxt, true, current application's NSUTF8StringEncoding, missing value)
end tell

it writes but rsync won’t exclude the lines with foreign chars ( like “/testPath/Jérôme”)

tell class "NSString" of current application
     set newstring to stringWithString_(excludeList)
     set clean_excludeList to excludeLists decomposedStringWithCanonicalMapping()
     clean_excludeList's writeToFile_atomically_encoding_error_(excludetxt, true, current application's NSUTF8StringEncoding, missing value)
end tell

now it reads that path and excludes it. So how do I do it without decomposedString…?

Should I use a different encoding for the writeToFile?

Rob

Sorry, I meant the writing problem using writeToFile_atomically_encoding_error_.

Are you using rsync with a non-OS X box? If so, I gather you can use a newer version of rsync that has an option (–iconv) that should handle the problem.

I forgot about --iconv. I am trying it so far with no luck but that’s an rsync question. For now the decomposed string does the trick till --iconv does what it should.

Cheers, Rob