ご入力いただきありがとうございます。次のAppleScriptについて質問があります。同じコマンドを2回実行し、2つの異なる応答を取得しています。最初はunixコマンド(grep)で、2番目は純粋なAppleScriptです。teXドキュメントで文字列、つまり\begin{document}を見つけようとしています。次に、AppleScriptでこの文字列の前に\usepackage{whatever}を追加します。アクティブなウィンドウのファイルの場所をTeXShopからpythonに渡すことができず、AppleScriptのみを渡すことができないことを除いて、私が望むことを実行するpythonスクリプトがあります。
質問:UNIXバージョンが純粋なAppleScriptバージョンと異なるのはなぜですか?\ begin {document}は、私がチェックしているドキュメントに確実に含まれていることに注意してください。純粋なバージョンは正しく機能します。
tell application "TeXShop"
-- get the front document and save
set thisDoc to the front document
-- get the filename and cursor position of the document
get path of thisDoc
set filePath to result
--set insPoint to offset of selection of thisDoc
end tell
set searchResult to do shell script "grep -q \\begin{document}" & filePath & "; echo $?" --echo 0 on match found/success and 1 on not found
if searchResult = "0" then
display dialog "string found"
else
display dialog "string not found"
end if
set findThis to "\\begin{document}"
set theFileContent to read filePath
if result contains findThis then
display dialog "string found"
else
display dialog "string not found"
end if