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

Michael Sharpe msharpe at ucsd.edu
Sat May 24 07:16:17 CEST 2014

On May 23, 2014, at 7:33 PM, Nicolae Garleanu <garleanu at haas.berkeley.edu> wrote:

> Beautiful ‹ I can build on this for other, perhaps more useful, instances.
> (A thought that came in this regard was a `macro recorder¹, as I came
> across elsewhere. You start it, then perform some tasks, commands, etc.,
> then stop. Output may be ugly, but functional. Doesn¹t Apple have
> something like this? I know that there exists an Automator, not quite sure
> what it can and cannot do.)
> In this case, I would probably want the macro to check whether the preview
> or source is active, o/w I have to run different macros/commands (since
> cmd-1 does not activate source, but rather toggles, as Herb explained, and
> I have since seen in the `Window¹ menu). For that purpose I am thinking of
> looking at the content of the code for the very command Cmd-1 (or maybe
> Cmd-T, which works from wherever). Where can I find these, though? Not in
> Macros.plst, I know, perhaps they are `hidden¹ somewhere? I can probably
> inspire myself from one of Claus Gerhardt¹s Macros. I also think that
> there is something about file names in the TexShop help.
> Nicolae
>> --applescript
>> tell application "TeXShop"
>> 	activate
>> 	tell application "System Events"
>> 		keystroke "1" using command down
>> 		keystroke "f" using command down --important to use lowercase
>> 	end tell
>> end tell
> -

You may find the following code snippet to be useful. It seems to be a reliable way to switch the focus from any one of the {.tex,.pdf, console} windows to the corresponding .tex window in TeXShop. If there's an easier way, I'd like to know it.

tell application "TeXShop"
	set doclst to documents --only the names of the tex docs
	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 with i from 1 to n
			key code 120 using {shift down, command down}
		end repeat
		-- at beginning of list of docs
		repeat with i from 1 to n
			if ((name of document 1) = doc1) then
				exit repeat
				key code 120 using command down	--cmd-F2			
			end if
		end repeat
	end tell
end tell


More information about the macostex-archives mailing list