[OS X TeX] 1) Search source file when preview is active (`front'). 2) Incremental search

Nicolae Garleanu garleanu at haas.berkeley.edu
Sun May 25 14:48:06 EDT 2014


Hi Michael,
Am I right that, if one is content with the ability to call the macro from
the .pdf and .tex files, then one can just do something like

if win ends with ".pdf" then
	tell application "System Events" to keystroke "1" using command down
end if
tell application "System Events" to keystroke "f" using command down

I.e., skip the loop dealing with consoles? Of course it can¹t hurt to have
it there anyway. In fact, what I had played with was to have cmd-1 be
executed anyway, since that way the latest .tex would be reactivated,
unless it was already active, in which case it remains the latest .tex.
(Code below.) Not meant to work with consoles, of course. For reasons I
don¹t understand, it doesn¹t always do what I expect it to, in that it
sometimes searches in the wrong .tex file, and also beeps as if there¹s an
error. May have to do with the way I change focus to the latest window?
Anyway, I¹ll implement your latest. As for ``applescript direct¹¹, I was
afraid that, since I needed to give input through GUI to perform the
search there may be a problem.


Nicolae


--applescript
tell application "TeXShop"
	activate
	tell application "System Events"
		keystroke "1" using command down
	end tell
	set p to (path of document 1)
	try
		open p as POSIX file
	on error errmsg number errnum
		if not (errnum = -1712) then
			display dialog "Error: '" & errmsg & "' trying to open document"
		end if
	end try
	tell application "System Events" to keystroke "f" using command down
end tell








>I think one has to go back to a variant of the prior version. The
>following works for me in both --applescript and --applescript direct
>modes (I prefer the latter):
>
>tell application "TeXShop"
>	activate
>	set win to name of window 1
>	if win ends with ".pdf" then
>		tell application "System Events" to keystroke "1" using command down
>	else if win ends with " console" then
>		set doclst to documents
>		set doc1 to (name of document 1) --always returns tex doc name
>		set n to ((count doclst) - 1)
>		tell application "System Events"
>			key code 120 using {shift down, command down} --shift-cmd-F2
>			repeat n times
>				key code 120 using {shift down, command down}
>			end repeat
>			--now at beginning of TeXShop's internal list of docs
>			repeat n times
>				tell application "TeXShop" to set thedoc to (name of window 1)
>				if (thedoc = doc1) then
>					exit repeat
>				else
>					key code 120 using command down --cmd-F2			
>				end if
>			end repeat
>		end tell
>	end if
>	tell application "System Events" to keystroke "f" using command down
>end tell



More information about the MacOSX-TeX mailing list