[OS X TeX] Applescript in TeXShop Questions

Claus Gerhardt gerhardt at me.com
Tue Mar 10 17:27:31 CET 2009


Attached are three scripts: The script "linenumber" gives the line  
number of the selection instantly.
The other two scripts use this script to reopen a tex document at a  
specified line.

Select a word in the line and then run the script "close_position", it  
will save the line number in a file filename.position. When  you  
reopen the tex file run the script "open_position", it will read the  
line number and tell TS to go to line.

Save the scripts as Macros. The close_position script could be  
combined with a close file command, if desired.

Claus

-------------- next part --------------
A non-text attachment was scrubbed...
Name: close_position.scpt.zip
Type: application/zip
Size: 7840 bytes
Desc: not available
URL: <http://tug.org/pipermail/macostex-archives/attachments/20090310/62248a59/attachment.zip>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: linenumber.scpt.zip
Type: application/zip
Size: 7254 bytes
Desc: not available
URL: <http://tug.org/pipermail/macostex-archives/attachments/20090310/62248a59/attachment-0001.zip>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: open_position.scpt.zip
Type: application/zip
Size: 6960 bytes
Desc: not available
URL: <http://tug.org/pipermail/macostex-archives/attachments/20090310/62248a59/attachment-0002.zip>
-------------- next part --------------



On Mar 10, 2009, at 15:17, Ram?n M. Figueroa-Centeno wrote:

> Aloha,
>
> 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
>
> and
>
> -- 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"
>    beep
> end tell
>
> and
>
> --Applescript direct
> beep
>
> 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".
>
> Sincerely,
>
> Ram?n
>
> -- 
>
> 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)
>
> http://www2.hawaii.edu/~ramonf/
>
> 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