Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'dangerous script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
dangerous script
Authored by: mzs on Oct 04, '05 08:50:52AM
Whenever you do POSIX path in an applescript and you want to pass the results to something you do from the shell, you need to escape it. The way to do that is with the "quoted form of" recipe. Beyond that the original script is dangerous since it evaluates the unescaped path which could have commands in it.

Anyway here is an improved script that also fixes that mistake.

# cd's to frontmost window of Finder
cdh() {
        eval cd `osascript -e '
        tell application "Finder"
                quoted form of POSIX path of (target of window 1 as alias)
        end tell
on error
end try

[ Reply to This | # ]
dangerous script - actually not
Authored by: mzs on Oct 04, '05 11:56:06AM
Since this uses the form "``" instead of just `` that aspect of the original script is okay. No word splitting etc happens in that case. For example:

$ echo 'foo  bar'
foo  bar
$ echo `echo 'foo    bar'`
foo bar
$ echo "`echo 'foo    bar'`"
foo    bar
So it is not incorrect, nor is it dangerous precisely because it DOES not do an eval. I feel pretty dumb now.

[ Reply to This | # ]