Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Textwrangler script
- -- Gets the Selected text from Textwrangler and executes it in R.
- -- Works for R.app or for command line R if R has already been started
- -- and is in the formost terminal window
- --
- -- Author: Spencer Bliven
- global myapp, editor, CurrLine
- -- Uncomment your favorite program for running R
- set myapp to "Terminal"
- --set myapp to "iTerm"
- --set myapp to "R"
- --set myapp to ""
- set editor to "TextWrangler"
- set CurrLine to my getCurrentLine()
- if myapp is equal to "Terminal" then
- tell application "Terminal"
- activate
- set mytab to selected tab of front window
- do script CurrLine in mytab
- end tell
- else if myapp is equal to "iTerm" then
- tell application "iTerm"
- activate
- set term to current terminal
- set ses to current session of term
- write ses text CurrLine
- end tell
- else if myapp is equal to "R" then
- tell application "R"
- activate
- cmd CurrLine
- end tell
- else if myapp is equal to "" then
- else
- display dialog "Don't know how to send lines to " & myapp
- end if
- to getCurrentLine() -- gets either the selected text or the line the cursor is on
- tell window 1 of application editor
- set sel to selection
- set SelLength to length of sel
- if SelLength > 0 then
- return sel as string
- else
- try
- set lineNum to startline of sel
- on error
- -- startline is sometimes missing from sel. Access it by the class name instead
- set lineNum to «class SLin» of sel
- end try
- set lineTxt to line lineNum as string
- return lineTxt
- end if
- end tell
- end getCurrentLine
Advertisement
Add Comment
Please, Sign In to add comment