Skip to content

Latest commit

 

History

History
91 lines (61 loc) · 6.65 KB

README.md

File metadata and controls

91 lines (61 loc) · 6.65 KB

textwrang

BBEdit Free (previously TextWrangler) is my text editor of choice on Mac. The files I use to customise BBEdit Free (TextWrangler) are stored here. See the below table for the organisation of this repository.

Directory Heading below Contents
syntax 1 .plist files for syntax highlighting of specific file types and .bbColorScheme files for colours schemes (version 5+)
as 2 AppleScripts to use with BBEdit

1. BBEdit and syntax highlighting

  • Users can create their own files to recognise syntax from different languages in BBEdit. The .plist files in the syntax directory can simply be copy and pasted into
    ~Library/Application\ Support/BBEdit/Language\ Modules/
    for BBEdit to recognise syntax for languages that don't already exist in BBEdit. You don't need to start from scratch, some languages are already here.

  • I prefer dark colour schemes when coding - this can manually be manufactured via preferences. In any case, I include a .bbColorScheme file that can be used to modify the appearance of BBEdit (for use in TextWrangler version 5 or above). Simply copy .bbColorScheme files to
    ~/Library/Application\ Support/BBEdit/Color\ Schemes/
    for colour themes to be usable by BBEdit.

Don't forget to quit and re-start BBEdit for the above changes to take effect.

2. BBEdit and AppleScripts

BBEdit not only allows you to run AppleScripts with user customisable key-strokes, but it has its own Scripting Dictionary that allows AppleScripts to interact with BBEdit (and other applications). These AppleScripts allow you to perform otherwise repetitive or time consuming task while working in BBEdit.

Example

As an example, the below AppleScript simply sends the selected text in BBEdit (or line if no text is selected) to Terminal.

tell application "BBEdit"
    set the_selection to (selection of front window as string)
    if (the_selection) is "" then
        set the_selection to line (get startLine of selection) of front window as string
    end if
end tell
tell application "Terminal"
    set shell to do script the_selection in window 1
end tell

How to make BBEdit aware of your AppleScripts

BBEdit has a folder specifically to hold AppleScripts it uses (that you write). You can find it by going
Script icon (next to Help) -> Open Scripts Folder

The location is likely to be ~/Library/Application\ Support/BBEdit/Scripts

Copy and paste your scripts (or those in this repository with file extension .scpt) to this folder. BBEdit should now be aware of your scripts. The names of the scripts in the folder should be seen under the Open Scripts Folder option when you click on the Script icon.

How to make key-bindings

Now that your scripts are available to BBEdit, you can go to
Window -> Palettes -> Scripts

Once the palettes window is open, you can assign key bindings to your available scripts. To do this, select a script and then press Set Shortcut; the key combination you press next is the new shortcut. Now any time you press control+space for example, BBEdit will run the script associated with that key binding.

List of AppleScripts in as folder

File Description
comment-line.scpt The text of the current line in BBEdit is surrounded by # characters (comment characters in R) to make the entire line a total of 88 characters wide (my page width). Good for make headers in code.
makefile-in-dir.scpt When invoked from BBEdit, the AppleScript changes the directory location of the open terminal, then runs make. Assumes there is a makefile file in the directory. Rob J Hyndman has a good introduction on these handy files.
pygmentize.scpt When an R file is the current document in BBEdit, the AppleScript runs Pygments command line utility on the current document. Pygments is a syntax highlighter, I use it to have syntax highlighted (and maths symbols in comments) in .tex files. This AppleScript could easily be modified to convert C++ code to syntax highlighted html, for example.
pygments-style.scpt Simple creation of the style file needed in the LaTeX preamble to allow syntax highlighting. relates to pygmentize.scpt.
selection-to-r.scpt Takes the selected text (or current line if no selection) and executes it in R. Attempts to move the cursor one line down once returning to BBEdit.
selection-to-sh.scpt Same as selection-to-r.scpt but sends it to Terminal.
tex-compile.scpt Requires a .tex or .Rnw (knitr) file to be the current document in BBEdit. If the file has a .Rnw file extension, the AppleScript 'knits' the file (evaluates the R code within the document via command line), then uses latex make (latexmk) to compile the resulting .tex file. If the file has a .tex file extension, the AppleScript simply runs latexmk on the file to compile the LaTeX file to PDF.
tex-eqn.scpt Places $ characters around the selected text. i.e. makes in-line equation text in LaTeX.
tex-itemize.scpt Makes each selected line an \item in an itemize list in LaTeX. Also places \begin{itemize} and \end{itemize} before and after the selection.
tex-texttt.scpt Places \texttt{ before the selected text and } after. i.e. makes the selected text typewriter font in LaTeX.

Acknowledgements

Firstly thank you to Bare Bones Software for making BBEdit available as a free version of their BBedit text editor. Even the documentation for the free version is pretty great.

I have used many websites to understand how AppleScripts work and used some other websites that have provided AppleScripts that are made for BBEdit. To the best of my memory and retrospective searching, thank you to the following:

  • The code written by Jean Thioulouse first alerted me to executing AppleScripts in BBEdit
  • Benjamin Waldie has an excellent run-through of manipulating text in AppleScripts
  • rupa for the shell script to extract source code from .scpt files