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 の結果ペインには、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 に答える