[R-SIG-Mac] Applescript window selection question

Rob J Goedman goedman at mac.com
Sat Sep 8 01:52:32 CEST 2007


John,

In textmate, below line is used:

osascript -e 'tell application "R.app" to activate' -e "tell  
application \"R.app\" to cmd \"source(file='$TM_FILEPATH',  
print.eval=TRUE)\""

I used similar constructs for SubEthaEdit and Smultron in AppleScript.

Try using tell **application**.

Rob


On Sep 7, 2007, at 1:33 PM, John Daschbach wrote:

> This is really an Applescript question, but I thought I would ask  
> here.
> What I really want is a reliable way to source() in R a buffer in  
> Emacs.
>
> How do you specify a certain window in the R interface using  
> Applescript?
>
> I am trying to use the R gui from Emacs.  The code at the end does  
> this,
> some of the time.
>
> The problem is that "tell window 1" addresses the window with focus  
> in R, so
> this only works when the console has focus.  If the Quartz window  
> or the
> Help window (or any other) has focus the Applescript fails.  This also
> usually, but not always fails after an exception is thrown in the  
> gui (R
> error)
>
> The window order in Applescript is the order from front to back.   
> However, I
> have been getting errors trying to get a window from it's name, e.g.
>
>     set nn to (get window whose name contains "Con")
>
> This throws an error.  Even
>
> set wn to (get name of window 1)
> set nn to (get window whose name contains wn)
>
> Does not work.
>
> Thanks.
>
> -John
>
> In Emacs:
>
> (defun R-source-buffer ()
>   (interactive)
>   (save-excursion
>     (let ((rbuf (current-buffer)))
>       (save-buffer-to-load-file "/tmp/tmp.R")
>       (shell-command "~/Common/Languages/Applescript/App/R01.app&")
>       ;;(kill-buffer "*Async Shell Command*"))
>       (pop-to-buffer rbuf))))
> ;;
> ;;  File name needs to be the same in the Applescript application
> ;;
> (defun save-buffer-to-load-file (fname)
>     (let ((ts (buffer-substring-no-properties (point-min) (point- 
> max))))
>       (write-region (point-min) (point-max) fname)))
>
> In Applescript:
>
>
> tell application "R"
>     activate
>     tell application "System Events"
>         tell process "R"
>             tell window 1
>                 keystroke "source('/tmp/tmp.R')"
>                 keystroke return
>             end tell
>         end tell
>     end tell
> end tell
>
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac



More information about the R-SIG-Mac mailing list