[OS X TeX] applescripts for TeXShop and iTeXMac?
Matthew Hills
hills_tex at tina.stanford.edu
Mon Aug 30 23:22:09 CEST 2004
On Aug 27, 2004, at 8:08 PM, Will Robertson wrote:
> 2. So, you'd think that you could fix this, as you suggested, with
>
> texapp = "TeXShop"
> tell application texapp
> ...
> end tell
>
To close out my own thread, I found that the "-- applescript direct"
tag in TeXShop 1.35 yields the desired solution. I've appended a toy
script to demonstrate it. I found that I needed to use a raw event
code for inserting text in iTeXMac (so that it would compile in both
without error and without opening both apps).
A few other notes for other scripters: there is a size limit to the
amount of text that can be passed in to the "choose item" dialog. It
appears to be about 65k characters.
BTW, I'm having problems with pasting scripts into Apple's Mail
program -- some characters get converted and it changes the line
wrapping...
Matt
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
-- applescript direct
on run
set front_app to get_front_app("", true)
-- get current selection
tell application front_app
if front_app = "TeXShop" then set sel_text to the content of the
selection of the front document
if front_app = "iTeXMac" then set sel_text to the selection of the
text of the front document
end tell
set out_text to "your selected text was: '" & sel_text & "'."
-- output text
tell application front_app
if front_app = "TeXShop" then set the selection of the front document
to out_text
if front_app = "iTeXMac" then tell front document to «event iTMyINST»
out_text in its text
-- Note: <<event iTMyINST>> is the insert event from the iTeXMac
Text dictionary...
end tell
end run
on get_front_app(default_target, scriptrunner_is_error)
try
tell the current application to set front_app to my name
if front_app is equal to "Script Editor" then set front_app to
default_tex_app
on error
if scriptrunner_is_error then
error "Unable to identify host application." & return & "Maybe you
are running from an old version of TeXShop? Or maybe the script does
not start with the line '-- applescript direct'?"
else
set front_app to "TeXShop"
end if
end try
return front_app
end get_front_app
--------------------- Info ---------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
& FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Post: <mailto:MacOSX-TeX at email.esm.psu.edu>
More information about the macostex-archives
mailing list