Hi I am resending this because I fear that the text that I sent for some reason didn't show up for most of you based on this … https://stat.ethz.ch/pipermail/r-sig-mac/2012-March/009116.html
This isn't too bump this post or cause I am impatient. I appreciate any help I can get.
Thanks. 
Hi,
I don't know if this is entirely the right place to ask this question and I apologize if it is inappropriate. Nonetheless, I am trying to set up BBEdit to use the Sweave.sh script. It seems that I could use AppleScript to do this. I have found http://msneep.home.xs4all.nl/latex/ which seemed pretty slick and I figured I could just edit one of his AppleScripts to get BBEdit to run Sweave.sh. Below is the AppleScript I am trying to run.

##################
(* Find out which editor is running. If both are running, it probably depends on which one was launched first (i.e. seemingly random) *)
tell application "System Events"
	try
		set callingEditor to 1st process whose name is "BBEdit"
	on error
		tell me to quit
	end try
	set appName to the name of callingEditor
end tell

(* Since BBEdit and TextWrangler use the same AppleEvents, we can get away with this. Of course AppleScript still needs to know what to emit. *)
tell application appName
	using terms from application "BBEdit"
		set numdocs to the number of every text document
		repeat with ii from 1 to numdocs
			if (modified of text document ii) then
				save text document ii
			end if
		end repeat
	end using terms from
end tell

(* If there are open documents, then "do your thing" *)
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)
	tell application "Terminal"
		set numterms to count windows
		if numterms > 0 then
			do script cmd in window 1
		else
			do script cmd
		end if
	end tell
end if

##################

And here is the output from the AppleScript replies

#################

tell application "System Events"
	get process 1 whose name = "BBEdit"
		--> application process "BBEdit"
	get name of application process "BBEdit"
		--> "BBEdit"
end tell
tell application "BBEdit"
	count every text document of current application
		--> 1
	get modified of text document 1
		--> false
	get file of active document of window 1
		--> file "Macintosh HD:Users:chris:Dropbox:Documents:university:classes:2011_2012:spring2012:stat5201:hw:hw5:stat5201_hw5.Rnw"
end tell
tell current application
	do shell script "/Users/chris/Library/TeXShop/bin/Sweave.sh -ld '/Users/chris/Dropbox/Documents/university/classes/2011_2012/spring2012/stat5201/hw/hw5/stat5201_hw5.Rnw'"
		--> error "Error in file(output, open = \"w\", encoding = encoding) : 
  cannot open the connection
Calls: Sweave -> <Anonymous> -> file
In addition: Warning message:
In file(output, open = \"w\", encoding = encoding) :
  cannot open file 'stat5201_hw5.tex': Permission denied
Execution halted" number 1
Result:
error "Error in file(output, open = \"w\", encoding = encoding) : 
  cannot open the connection
Calls: Sweave -> <Anonymous> -> file
In addition: Warning message:
In file(output, open = \"w\", encoding = encoding) :
  cannot open file 'stat5201_hw5.tex': Permission denied
Execution halted" number 1

#################

So it appears I am having a Permission error or something. I wonder if I haven't told AppleScript to save the output to the correct directory? I can attach the .Rnw file but that isn't the problem.

Thanks,
Chris 


	[[alternative HTML version deleted]]


	[[alternative HTML version deleted]]

