Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: BBEdit and Stata
From
FE Statalist <[email protected]>
To
[email protected]
Subject
Re: st: BBEdit and Stata
Date
Wed, 24 Nov 2010 08:29:44 +1100
> I don't use BBEdit, but use Coda (best text editor I've used on the Mac).
> Anyway, I added the exact behaviour you describe using AppleScript. Below is my AppleScript code you might be able to tweak to work with BBEdit.
> It essentially creates a temporary .do file with your code and is opened in Stata. There may be more elegant ways of doing this, but this worked for me (path of least resistance).
> I've also put together a Stata Syntax Mode for Coda, and a number of clips (snippets inserted with quick keystrokes). If anyone's interested, I'm happy to share.
>
> This is triggered in Coda by pressing Shift + AppleKey + D (run selected lines):
>
> -- script settings
> on CodaScriptSettings()
> return {displayName:"Do Selection", inContextMenu:"yes"}
> end CodaScriptSettings
>
> set openURL to ""
>
> -- actual script
> tell application "System Events"
> --Delete temporary do file if it exists
> try
> do shell script "rm /coda2StataTempSel.do"
> end try
> end tell
>
>
> tell application "System Events"
> --Get the code to execute in Stata
> tell application "Coda"
> activate
> try
> tell current split of front document
> --Get selected range cooridantes
> set stataCode to selected range
> set startCharIndex to item 1 of stataCode
> set selectedTextLength to item 2 of stataCode
> set endCharIndex to startCharIndex + selectedTextLength
>
> --Loop over selected characters, writing them to an output string
> set curCharacters to characters of contents
> set stataCode to "***This is a temporary do file. Can delete anytime
> "
> repeat with currentIndex from startCharIndex to endCharIndex
> set char to item currentIndex of curCharacters
> --Collect characters to string
> set stataCode to stataCode & char
> end repeat
> end tell
> end try
> end tell
>
> --Write the outputString to a do file
> set theFilePath to "coda2StataTempSel.do" as string
> set theFileReference to open for access theFilePath with write permission
> write stataCode & "
> " to theFilePath
> close access theFileReference
>
> --Execute the temporary do file
> tell application "StataSE"
> activate
> open POSIX file "/coda2StataTempSel.do"
> end tell
>
>
>
> --Return focus to results window of Stata
> tell application "System Events"
> keystroke "4" using {command down}
> end tell
> end tell
>
>
> This is triggered in Coda by pressing Shift + AppleKey + R (run entire file):
>
> --This script gets text from Coda to Stata
> --It is meant to get the entire contents of the file
> --,write it to a temporary do file, and execute that temporary
> --do file.
>
> -- script settings
> on CodaScriptSettings()
> return {displayName:"Run Do File", inContextMenu:"yes"}
> end CodaScriptSettings
>
> set openURL to ""
>
> -- actual script
> tell application "System Events"
> --Delete temporary do file if it exists
> try
> do shell script "rm /codaToStataTemp.do"
> end try
> end tell
>
>
> tell application "System Events"
> --Get the document contents
> tell application "Coda"
> activate
> try
> tell current split of front document
> set stataCode to contents
> end tell
> on error
> beep return
> end try
> end tell
>
> --Write contents to temporary do file
> set theFilePath to "codaToStataTemp.do" as string
> set theFileReference to open for access theFilePath with write permission
> write "**This file can be deleted anytime.
> " to theFileReference
> --Write an extra line ending character, otherwise Coda will fail to supply end of doc line
> write stataCode & "
> " to theFileReference
> close access theFileReference
>
> --Execute the temporary do file
> tell application "StataSE"
> activate
> open POSIX file "/codaToStataTemp.do"
> end tell
>
> --Return focus to results window of Stata
> tell application "System Events"
> keystroke "4" using {command down}
> end tell
>
> end tell
>
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/