[OS X TeX] Still trying...
Curtis Clifton
curt.clifton at mac.com
Wed Apr 7 11:31:10 EDT 2004
Herb,
On Apr 7, 2004, at 10:14 AM, Herb Schulz wrote:
> I'm back to trying to write an Applescript that does a search for the
> next
> occurrence of a particular character and then select that character
> within
> TeXShop. I can get the search to work fine but that doesn't select the
> character, it returns the character position in the file. Even though
> selection is a defined object in the TeXShop Applescript library I get
> an
> error when I try to set its position, length and contents to the
> required
> value. Is it read only?
I recall successfully setting the selection in TeXShop via Applescript
in the past, but I can't find the code that I used. Below is a script
that I use which includes some selection manipulation. The script
changes the contents of the selection and then repositions the point
inside the selection. I'm not sure it will be directly useful, but it
may inspire some ideas and is a useful script in its own right.
Curt
----------------------------------
Curtis Clifton, Graduate Student
Dept. of Computer Science, Iowa State University
http://www.cs.iastate.edu/~cclifton
--Applescript
-- Prompts the user for the name of an environment.
-- Surrounds the current selection with \begin{env} and \end{env}
-- where env is the given environment name.
-- by Curtis Clifton, http://www.cs.iastate.edu/~cclifton
property theEnv : "itemize" as Unicode text
property beginCmdPrelude : "\\begin{" as Unicode text
property cmdEnd : ("}" & return) as Unicode text
property endCmdPrelude : ("\\end{") as Unicode text
set advanceOffset to 8
try
activate
set theReply to (display dialog "Enter the environment name:" default
answer (theEnv as text) buttons {"Cancel", "OK"} default button "OK")
set theText to (text returned of theReply)
set theEnv to (theText as Unicode text)
set advanceOffset to advanceOffset + (length of theText)
tell application "TeXShop"
activate
tell selection of document #DOCUMENTNAME#
set originalOffset to offset
set content to (beginCmdPrelude & theEnv & cmdEnd & content &
endCmdPrelude & theEnv & cmdEnd)
set offset to (originalOffset + advanceOffset)
end tell
end tell
on error number errorNumber
if errorNumber is -128 then
-- User cancelled
else
error errorNumber
end if
end try
-----------------------------------------------------
Please see <http://www.esm.psu.edu/mac-tex/> for list
guidelines, information, and LaTeX/TeX resources.
More information about the MacOSX-TeX
mailing list