Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7801931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:06:06+00:00 2026-06-02T01:06:06+00:00

Thanks in advance for your input. I have a question regarding the following AppleScript.

  • 0

Thanks in advance for your input. I have a question regarding the following AppleScript. I am running the same command twice and getting two different responses.First a unix command (grep) and second pure AppleScript. I am trying to find a string, namely \begin{document} in a teX document. I want to then add a \usepackage{whatever} before this string with AppleScript. I have a python script which does what I want except that I can’t pass the file location of the active window from TeXShop to python, only AppleScript.

Question: Why does the unix version differ from the pure AppleScript version? Keep in mind the \begin{document} is most certainly in the document I am checking. The pure version works correctly.

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:06:08+00:00Added an answer on June 2, 2026 at 1:06 am

    The shell interprets special characters, in this case both backslash and braces; and grep and AppleScript itself also interpret backslashes.

    set searchResult to do shell script "grep -q '\\\\begin{document}'" & filePath & "; echo $?"
    

    The single quotes protect the braces and prevent the shell from parsing the backslashes; you need 4 backslashes because AppleScript eats one of each (for the same reason you need two backslashes in the pure AppleScript version) and grep eats the other (backslash means “treat the next character as literal”, except in GNU grep where it sometimes means “treat the next character as special” but that doesn’t happen here).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

thanks in advance for your input. I have 3 objects: School Camp Coach With
I have another question for the masses out there regarding trying to input values
Thanks in advance for your help experts. I want to be able to copy
First off, thanks in advance for your help. This issue is driving me nuts.
Thanks in Advance for reading and answer this question. I got button in asp
Thanks in advance.. I have a windows phone application. In that I am showing
thanks in advance for the replies.... I have started to create a network topology
I have the next question, I'll like to have TWO minimun values, a maximun
thanks in advance for taking the time to read through my question... /* Binary
I have a question regarding the verification of executable files, compiled with visual studio,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.