Secure way to reverse "quoted form of"

Hi m8s!

Does anybody of you know a secure way to get back the pure (non-escaped) path of a quoted file path?
Removing just the first and last characters only works if the path did not contain any escaped characters.

Lemme give you an example:


set foo to "/The/File/Path/To/Steve's File.txt"
set foobar to quoted form of foo
--result: "'/The/File/Path/To/Steve'\\''s File.txt'"

So what if I only have the value of variable “foobar” and I want to have it reversed to what variable “foo” looks like?

Do you know a secure way to do this? It must be compatible with any given characters in the file path

TIA,
Vincent

Hi,

As long as you know the text is quoted, try this:

set foobar to "'/The/File/Path/To/Steve'\\''s File.txt'"
set foo to unQuotedForm(foobar)

on unQuotedForm(myText)
	set {myTID, my text item delimiters} to {my text item delimiters, "\\''"}
	set myArray to text items of myText
	set my text item delimiters to myTID
	set myNewText to (characters 2 thru -2 of (myArray as Unicode text) as Unicode text)
	return myNewText
end unQuotedForm

John M

Since ‘quoted form of…’ is primarily used to properly quote things in a shell script, the simplest solution is to have the shell script undo the work:

set foo to "/The/File/Path/To/Steve's File.txt"
set foobar to quoted form of foo
do shell script "echo " & foobar
--> /The/File/Path/To/Steve's File.txt

:lol: How can I be such a dumbass?:rolleyes::mad:

That’s plain simple! Thank you all!

Me too. Never occurred to me that a simple “echo” would undo it. :lol: