MySQL socket port on Mac OS X

Every time I reinstall my system software, or set up a new machine, I break phpMyAdmin’s socket connection. Recently, information in this post helped me sort it out.

First, find out where MySQL is putting its socket:

> /usr/local/mysql/bin/mysqladmin variables
| socket     | /tmp/mysql.sock|

And then point phpMyAdmin to it by changing these lines in the file:

$cfg['Servers'][$i]['socket']   = '/tmp/mysql.sock';
$cfg['Servers'][$i]['connect_type']  = 'socket';

You might also (or instead) need to create a link from where MySQL has its socket to the location in which PHP thinks the socket should be:

>sudo ln -h /tmp/mysql.sock /var/mysql/mysql.sock

Finding your MAN

For some reason, my Mac OS X 10.8.2 installation keeps forgetting where my MAN pages are:

>man launchctl
No manual entry for launchctl
>echo $MANPATH

Apparently they’re in /usr/share/man, so we can append this proper path to the existing path with:

>export MANPATH=$MANPATH:/usr/share/man

>echo $MANPATH

Changing colour schemes in BBEdit

An old script that I used to change the colour scheme of BBEdit, based on John Gruber’s BBColors tool. This script is no longer necessary with BBEdit 10. You can, however, download John’s colour schemes and copy them to your “~/Library/Application Support/BBEdit/Color Schemes/” folder and then load them from the Text Colors section of BBEdit’s preferences.

tell application "System Events"
   set bbOpen to (name of processes) contains "BBEdit"
end tell

if bbOpen is true then
   tell application "BBEdit" to quit
end if

set btnSet to {"Cancel", "Light", "Dark"}
set prompt to "Do you want light or dark colours?"
set dlgResult to display dialog prompt buttons btnSet default button {"Dark"}

set btn to button returned of dlgResult
if btn is "Light" then
   set colourFileName to "Defaults"
else if btn = "Dark" then
   set colourFileName to "Gruber Dark"
end if

set shellScript to "bbcolors -load " & quote & colourFileName & quote
do shell script shellScript

tell application "BBEdit"
end tell

Using R and BBEdit

The statistical programming environment R is very powerful. The Mac text editor BBEdit is also very powerful. Together they are the ultimate combination. Luckily, with minimal effort you can make them very happy bedfellows. Here are two ways of integrating R with BBEdit.

Syntax colouring
Download the R syntax colouring file and move it to your “~/Library/Application Support/BBEdit/Language Modules/” folder.

Running code from within BBEdit
Two AppleScripts based on a post on an R mailing list. The first script will run the current selection (or line if there is no selection) in R. The second script will run the entire file in R. Save these scripts into your “~/Library/Application Support/BBEdit/Scripts/” folder. You can then go to Window -> Palettes -> Scripts and assign some shortcut keys to these scripts. I use Command-R to run the file, and Command-Option-R to run the line.

Open up Applescript Editor and paste these chunks of code into two separate files.

Save this file as ‘Run file in R’:

tell application "BBEdit"
   set theFile to (file of document of front window as string)
   set theFilePath to POSIX path of theFile
end tell

tell application "R"
   if theFile is "missing value" then
      cmd "print(" & quote & "Error: BBEdit file is not saved" & quote & ")"
      cmd "source(" & quote & theFilePath & quote & ")"
   end if
end tell

Save this file as ‘Run line in R’:

tell application "BBEdit"
    set theText to (selection of front window as string)
    if (theText) is "" then
        set theText to line (get startLine of selection) of front window as string
    end if
end tell

tell application "R"
    cmd theText
end tell

Jonathan Marc Bearak has some similar tips on his R & BBEdit integration page.