2

我知道这已经被反复询问过,例如,这里这里

但既不使用 \" 也不quote似乎对我有用。例如,使用

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

返回

"\"05-06-2013\""

我不明白为什么,如果你能启发我,那就太好了!如果这很重要,我正在使用 10.8.5 和德语本地化...

编辑:

这是我要开始工作的脚本

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

我得到一个错误,因为the_script没有正确设置,导致

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

无法正确执行...

4

1 回答 1

1

我认为,发生的事情是 AppleScript Editor 中的 Result 窗格向您显示了一个变量,就像您在 AppleScript 中使用它一样。

因此,当结果返回为 05-06-2013 被引号包围时,它会将其解释为字符串。并且因为,如果您将一个带有引号的字符串分配给一个变量,您将不得不反斜杠这些引号,它也在这里这样做。

您可以通过向脚本添加一些显示对话框来更好地了解正在发生的事情:

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

当显示为普通文本时,您会看到日期被引号包围。

对于新表单,这可能对测试有用:

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
于 2013-10-25T00:13:47.103 回答