[OS X TeX] Applescript in TeXShop Questions

Ramón M. Figueroa-Centeno ramonf at hawaii.edu
Tue Mar 10 15:17:58 CET 2009


I have three questions about TeXShop's Applescript implementation.

1. Does anybody know what are the differences between the following two code
snippets that can be run from the as Macros in TeXShop:

-- Applescript direct
set the front_document to the front document
set texpath to the path of the front_document


-- Applescript direct
set the front_document to document #DOCUMENTNAME#
set texpath to the #FILEPATH#

If they are functionally the same, then I rather use the first, because I
can run scripts written that way from the "Script Editor" application while
I am writing them.

The TeXShop manual says:

"#DOCUMENTNAME# is replaced with the display name of the current document.
This [...] is somewhat subtle; it gives the title of the document as shown
at the top of the source window. If a document was saved with the 'hide
extension' box checked, #DOCUMENTNAME# will contain only the document name.
But if the document was saved without checking 'hide extension',
#DOCUMENTNAME# will contain the document name and extension."

2. The following two snippets do the same thing:

--Applescript direct
tell application "TeXShop"
end tell


--Applescript direct

The first snippet, again, has the advantage that it can be run from the
"Script Editor". So it is nice to use to develop scripts. So my question is:
does the second snippet execute somehow better (e.g., faster) from within
the TeXShop Macros' Menu, than the first?

3. Is there a better way to figure out the line (paragraph) number of the
current selection in TeXShop than the following (run from the Script Editor
or from TeXShop's Macros' menu):

--Applescript direct
tell application "TeXShop"
    set the front_document to the front document
    -- The whole text of the document
    set whole_document to (the text of the front_document) as string
    -- The offset of the selection
    set selection_offset to offset of the selection of the front_document
    -- The document up to the selection
    set partial_document to (characters 1 thru (selection_offset) of the
whole_document) as string
    -- Let selection_line_number be the number of the line of the start of
the current selection
    set selection_line_number to count paragraphs of the partial_document
    set report to "selection line: " & selection_line_number & return
    display dialog selection_line_number
end tell

If the front document is large and the selection is near the end, then the
above is not a nice way of doing things.

It would be so nice if TeXShop understood something like "paragraph number
of the selection".




Ramón M. Figueroa-Centeno, Ph.D.
Associate Professor

Mathematics Department
University of Hawaii at Hilo
College Hall 4-A
200 W. Kawili St.
Hilo, HI 96720-4091

(808) 974-7387 (office)
(808) 933-3473 (fax)


PGP/GnuPG Public Key at http://www2.hawaii.edu/~ramonf/ramonf.gpgkey

----------- Please Consult the Following Before Posting -----------
TeX FAQ: http://www.tex.ac.uk/faq
List Reminders and Etiquette: http://email.esm.psu.edu/mac-tex/
List Archive: http://tug.org/pipermail/macostex-archives/
TeX on Mac OS X Website: http://mactex-wiki.tug.org/
List Info: http://email.esm.psu.edu/mailman/listinfo/macosx-tex

More information about the macostex-archives mailing list