This is a Mac specific question. I would like to source a script that I'm editing on Textmate2, e.g. mycode.R, and make it run in iTerm (terminal would do as well). I do not need to start R, I have the top window of iTerm already running it.
So in the iTerm tab should appear the line:
> source("[path]/mycode.R", chdir = TRUE)
What I needs equivalent to what you have on Rstudio with the key combination Cmd + Shift+S
. I found this answer How can I send selected text (or a line) in TextMate to R running on Terminal, but this is about sending a line, or echo the entire code, while what I need should be easier. I succeeded in sourcing to R.app using the following code
#!/bin/bash
osascript -e 'tell application "R.app" to activate'
osascript -e "tell application \"R.app\" to cmd \"source(file='"$TM_FILEPATH"',print.eval=TRUE, chdir=TRUE)\"" \
osascript -e 'tell application "TextMate" to activate'
But if I replace "R.app" by "iTerm", "iTerm2" or "Terminal", the script fails.