Applescript problems with quoted form of paths returned from iPhoto

Hi,
I’m having problems with quoted form of paths returned by iPhoto. For example:

set theEscapedFile to quoted form of (image path of thisPhoto as Unicode text)

should work fine but when the image path contains for example a " character it will not be escaped. Strangely enough when entering a character it will be escaped but not like this ' but like this '"

This will of course cause some major problems when trying to batch through a iPhoto library causing all kind of errors. So I tried a different approach:

set theEscapedFile to "" as Unicode text
set escapable_characters to " !#^$%&*?()={}[]'`~|;<>/\"\\" as Unicode text

repeat with chr in theFile
	if (escapable_characters contains chr) then
		set theEscapedFile to theEscapedFile & ("\\" as Unicode text)
	end if
	set theEscapedFile to theEscapedFile & chr
end repeat

This seemed to work pretty well until one day when a user tried it on a japanese system. Where the \ character suddenly were replaced by a yen character which apparently is located at the same place as the backslash on a european keyboard.

How to solve this?

Escaped how? These are escaped from AppleScript; They shouldn’t need any more protection from a shell because of the single quotes.

You really describe what you’re doing with that path and what you mean by “major problems” when you “batch” these items.

Also, where does theFile come from in your other script?

Part of your problem may be your usage of as Unicode text. When you pull an image path from iPhoto, it is already formatted properly for use by the shell, if that is what you want. You simply need to use the quoted form as you are doing already. Here is some example code from my super duper nifty DisplayMan:

set all_paths to the image path of every photo in album (item 1 of b)
repeat with a_path in all_paths
		do shell script "ln " & (quoted form of a_path) & space & ((quoted form of posix_disp) & "DispImage" & img_count & "." & fext)
end repeat

This is not a working script; simply an example of how I use image path to send a command to the shell.

My DisplayMan script is editable, and you are welcome to download it from ScriptBuilders, and examine the script in any script editor.

Good luck, I hope this helps.

Thank you for your rapid answers. It made me reting some things and now everything seems to work as it should.