Question

I know this has been asked repeatedly, e.g., here, or here,

but neither using \" nor quote does seem to work for me. E.g., using

set msgDate to "05-06-2013"
set quotedmsgDate to "\"" & msgDate & "\"" as string
do shell script "echo " & quoted form of quotedmsgDate

returns

"\"05-06-2013\""

I don't get why, it would be great if you could enlighten me! I am using 10.8.5 and German localization if that matters...

EDIT:

This is the script I am trying to get to work

tell application "BibDesk (original)"
    set thePublications to selection of document 1
    repeat with thePub in thePublications
        tell thePub
            if value of field "Pages" is not "" then
                set the_pages to value of field "Pages"
                set quoted_pages to "\"" & the_pages & "\"" as string
                set the_script to "/usr/bin/python /Users/Januz/Downloads/sanitize_BibDesk_pages.py -p " & quoted form of quoted_pages
                set a to do shell script the_script
                set value of field "Pages" to a
            end if
        end tell
    end repeat
end tell

I get an error because the_script is not set correctly, resulting in

do shell script "/usr/bin/python /Users/Januz/Downloads/sanitize_BibDesk_pages.py -p '\"151-65\"'"

which cannot be executed correctly...

Was it helpful?

Solution

What’s happening, I think, is that the Result pane in AppleScript Editor is showing you a variable as you would use it in AppleScript.

So when the result comes back as 05-06-2013 surrounded by quotes, it interprets this as a string. And because, if you were assigning a string with quotes in it to a variable you would have to backslash those quotes, it does so here as well.

You can get a better idea of what’s happening by adding some display dialogs to your script:

set msgDate to "05-06-2013"
set quotedmsgDate to "\"" & msgDate & "\"" as string
display dialog quotedmsgDate
set echoScript to "echo " & quoted form of quotedmsgDate
display dialog echoScript
do shell script echoScript
display dialog the result

When displayed as normal text, you’ll see that the date is surrounded by quotes.

For the new form, this might be useful for testing:

set the_pages to "151-65"
--set quoted_pages to "\"" & the_pages & "\"" as string
set quoted_pages to the_pages as string
set the_script to "/usr/bin/python /Users/Januz/Downloads/sanitize_BibDesk_pages.py -p " & quoted form of quoted_pages
display dialog the_script
set a to do shell script the_script
display dialog a
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top