problems with reading a plist file (special chars returned as octal)

Hello!

I ´m writing some preferences of an AppleScript Studio application to a plist file:

set contents of default entry "Host" to (hostname as Unicode text)

This works, but I want to read this value with an non-studio script. For this I use the following code:

		tell application "System Events"
			set Hostname to get value of property list item "Host" of property list file workingFileName as string
		end tell

Everything is ok. But this works only with Tiger. I need some code which works also with 10.2, 10.3.
I tried to read the plist file with this shell command:

set Hostname to (do shell script "defaults read de.foo.myFile Host ")

This works too. But the problem is, when I have saved a string which contains special chars like ü (german umlaut), then I get the octal number of the letter as result. I don ´t need the octal value, I need the real letter in the string.

Has someone a solution for my problem? That will be very nice.

Thanks and merry christmas, hoschy07.

Have you tried using one of XMLLib or XML Tools? (see Osaxen.com)

Otherwise, you may need a Octal to Text converter… (ask again if needed)

Hi jj!

Thank you for your reply. The best solution for me would be, if I must not install a scripting addition.
You mentioned a Octal to Text converter. How does this work? With or without a scripting addition?
It will be nice, if you could say more about the octal to text converter.

hoschy07.

Something as:

set oct to "\\0207"
ASCII character (do shell script "printf '%d' " & oct) --> "á"

But perhaps there is a different and faster workaround (?)

This question is maybe a little bit stupid: But how can I extract octal values from a string?

e.g.: set foo to “my\0207Special\0227string\0207also withnumbers92\0215andspaces”

set foo to "my\\0207Special\\0227string\\0207also withnumbers92\\0215andspaces"
--> "myáSpecialóstringáalso withnumbers92çandspaces"

doIt(foo)

to doIt(foo)
	set AppleScript's text item delimiters to "\\"
	set fooChunked to foo's text items
	set AppleScript's text item delimiters to {""}
	
	repeat with i from 2 to count fooChunked --> ignore first one
		try
			set chunk to text 1 thru 4 of fooChunked's item i
			chunk as number --> it's a backslash followed by four numbers!!!
			set foo to sr("\\" & chunk, ASCII character (do shell script "printf '%d' " & ("\\" & chunk)), foo)
		end try
	end repeat
	
	return foo
end doIt

to sr(s, r, t)
	set AppleScript's text item delimiters to s
	set t to t's text items
	set AppleScript's text item delimiters to r
	set t to t as text
	set AppleScript's text item delimiters to {""}
	t
end sr

Though this works, it smells it isn’t the faster and better way to do it… Hmmm…

Are you sure you can’t use a different method?

Damn! Ok, you are the boss! This is really cool!
Your solution works and this methods are fast enough. If everybody would be 10.4 installed, programming would be easier.
Thank you for your help.