Escaping shell script paths (was: Photo Processing , Gallery and IPTC Data app)
Ian Wood
revlist at azurevision.co.uk
Fri Feb 1 03:52:28 EST 2008
On 28 Jan 2008, at 10:31, Ian Wood wrote:
> function ijwAPLIB_MakeOSXShellPath tPath
> put "set tOut to quoted form of POSIX path of tPath" into tScript
> replace "tPath" with quote & revMacFromUnixPath(tPath) & quote in
> tScript
> do tScript as applescript
> put the result into tNewPath
> delete char 1 of tNewPath
> delete last char of tNewPath
> return tNewPath
> end ijwAPLIB_MakeOSXShellPath
Oops. Just discovered that the above function doesn't cope with file
paths that contain any kind of quote mark.
The following function should work better, escaping characters rather
than putting quote marks around the whole path.
Can anyone think of other problems that might crop up when converting
Rev paths to escaped paths for use in OS X shell scripts? I think I've
got all the command characters that can actually be used in legal file
names.
function ijwAPLIB_MakeOSXShellPath tPath
put "set tOut to POSIX path of tPath" into tScript
replace "tPath" with quote & revMacFromUnixPath(tPath) & quote in
tScript
do tScript as applescript
put the result into tNewPath
delete char 1 of tNewPath
delete last char of tNewPath
replace space with "\" & space in tNewPath
replace quote with "\" & quote in tNewPath
replace "'" with "\" & "'" in tNewPath
replace "*" with "\" & "*" in tNewPath
replace "?" with "\" & "?" in tNewPath
replace "[" with "\" & "[" in tNewPath
replace "]" with "\" & "]" in tNewPath
replace "{" with "\" & "{" in tNewPath
replace "}" with "\" & "}" in tNewPath
replace "$" with "\" & "$" in tNewPath
replace "!" with "\" & "!" in tNewPath
replace "&" with "\" & "&" in tNewPath
replace "|" with "\" & "|" in tNewPath
replace ">" with "\" & ">" in tNewPath
replace "<" with "\" & "<" in tNewPath
replace ";" with "\" & ";" in tNewPath
replace "(" with "\" & "(" in tNewPath
replace "(" with "\" & ")" in tNewPath
return tNewPath
end ijwAPLIB_MakeOSXShellPath
Ian
More information about the use-livecode
mailing list