[R-SIG-Mac] Sweave.sh, BBEdit, and AppleScript

Berend Hasselman bhh at xs4all.nl
Wed Mar 21 15:40:16 CET 2012

On 21-03-2012, at 13:48, Christopher David Desjardins wrote:

> if numdocs > 0 then
> 	tell application appName
> 		using terms from application "BBEdit"
> 			set mypath to get file of active document of window 1
> 		end using terms from
> 	end tell
> 	set cmd to do shell script "/Users/chris/Library/TeXShop/bin/Sweave.sh " & "-ld "  & (the quoted form of POSIX path of mypath)

This line is incorrect. It should read

	set cmd to "${HOME}/bin/Sweave.sh " & "-ld "  & (the quoted form of POSIX path of mypath)

But don't call Sweave.sh directly. Doesn't seem to work properly in BBEdit.
(At least not for me)

Create a runSweave.sh script:

# run Sweave.sh in directory of input file

cd $(dirname "$1") 
${HOME}/bin/Sweave.sh -ld $(basename "$1")

This seems to be 
and replace the line mentioned above with

	set cmd to "${HOME}/bin/runSweave.sh " & (the quoted form of POSIX path of mypath)

Furthermore make sure that Sweave.sh and runSweave.sh are executable.

You should have a symbolic link in ${HOME}/Library/texmf/tex to 


so that latex can find Sweave.sty.

This worked for me.

In the end it seems that you can just as well skip the Applescript thing and just make a runSweave shell script.
See the manual on Unix scripting.


More information about the R-SIG-Mac mailing list