[OS X TeX] Working with a root file in BBEdit

Claus Gerhardt gerhardt at math.uni-heidelberg.de
Sat Nov 27 00:49:41 CET 2004


Below is an Applescript that can be copied to the beginning of any of 
my  Applescripts that are supposed to run on a .tex file. The script 
will search the first three lines of the front document for the 
presence of

%Source Doc%relativePathofrootFile  (ending in .tex), e.g.,

%Source Doc%../master.tex

and will open the root file, if one is specified, and run the rest of 
the script on the root file. If no root file is specified, then the 
main part of the script runs on the current document.

Claus


tell application "BBEdit"
	get file of window 1
	set filepath to result
	set fileName to POSIX path of filepath as string
	
	set scriptPath to (do shell script "dirname " & 
"~/Library/TeXShop/Scripts/ex")
	set scriptPath to scriptPath & "/setnamebbedit.scpt"
	set scriptName to POSIX file scriptPath as alias
	set scriptLiB to (load script scriptName)
	tell scriptLiB
		set {baseName, texName, pdfName, namePath, dirName, dirNameunquoted, 
logName, logPath, rtfName} to setnamebbedit(fileName)
	end tell
	
	set foundboolean to "false"
	try
		find "%Source Doc%(.+\\.tex)" searching in lines 1 thru 3 of text 1 
of text window 1 options {search mode:grep, starting at top:true, wrap 
around:false, backwards:false, case sensitive:false, match words:false, 
extend selection:false} with selecting match
		set {foundboolean, foundText} to {found of result as string, found 
text of result}
	end try
end tell
if foundboolean is equal to "true" then
	set n to (number of characters of contents of foundText)
	set i to 2 as number
	
	repeat while i < (n + 1)
		if character i of foundText is equal to "%" then
			set k to i
			exit repeat
		else
			set i to (i + 1)
		end if
	end repeat
	set texFile to (characters (k + 1) thru n of foundText as string)
	set dirName2 to do shell script "dirname " & texFile
	set texName to do shell script "basename " & texFile
	
	set shellScript to do shell script "/usr/bin/bbedit " & dirName & "/" 
& dirName2 & "/" & texName
	do shell script shellScript
end if

--------------------- 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