This page describes one way of turning the standard sage directory into a clickable Mac Application.

The [ Platypus] program is used to make things easier. Download Platypus, and install it along with its command line tool. Using the Platypus command line program makes this process scriptable.

A Mac application needs an Icon. I made one from the Sage web site logo using the Icon Composer program that is installed with Apple's Xcode tools. Name the icon sage.icns

Next, a small Python program called is useful to set things up. This program will create a .command file so that OS X will start Sage in the program, update the SAGE_ROOT variable to reflect the current location of the program, and finally start the program. Updating SAGE_ROOT automatically allows users to drag the program to install it.

This is the full contents of

   1 import sys, commands, string, os
   3 # path to inside of
   4 appname = string.join(string.split(sys.argv[0], '/')[:-3], '/')
   5 sageDir = appname + '/Contents/Resources/sage'
   6 sageScriptOrig = sageDir + '/sage'
   7 sageScriptNew = sageDir + '/sageMac.command'
   9 # copy Sage startup script to end in .command so that OS X will launch it 
  10 commands.getoutput('cp -f %s %s' % (sageScriptOrig, sageScriptNew))
  12 # edit sageScriptNew to reflect current location (sageDir)
  13 f = open(sageScriptNew)
  14 lines =
  15 f.close()
  17 splitLines = string.split(lines, '"')
  18 newLines = [splitLines[0], sageDir]
  19 newLines.extend(splitLines[2:])
  20 newLines = string.join(newLines, '"')
  22 f = open(sageScriptNew, 'w')
  23 f.write(newLines)
  24 f.close()
  26 # run the script
  27 os.execl('/usr/bin/open', '/usr/bin/open', sageScriptNew)

With sage.icns,, and a current sage directory for your platform (e.g., Intel, OS X 10.5), the Mac application can be built with this command:

platypus -t python -i sage.icns -f sage

This takes a while to execute, because it has to copy all of Sage, but when it completes there should be a nice clickable Mac application called in your folder. You can drag this to your Applications folder to install it, and double click on it to start Sage in a terminal window.

It is good to be able to run Sage from the command line as well. This can be enabled by creating a symbolic link to the sageMac.command script inside of the Mac application, for example (one long line):

sudo ln -s /Applications/ /usr/local/bin/sage

Be aware that the sageMac.command file will not exist until is run for the first time, so don't try to create the link until after Sage has been run once.

Finally, the program can be packaged up for distribution in a compressed disk image with a readme.txt file using a procedure like this:

# make a compressed Sage disk image for distribution (specific to this platform):
export platform="10.5intel"
export version=`sage/sage --version | sed s/,// | cut -f 3 -d' '`
hdiutil create -fs HFS+ -size 1500m -volname Sage Sage
hdiutil attach Sage.dmg
cp -R /Volumes/Sage
# copy anything else you want in the distribution, such as a 'readme.txt' file
cat > /Volumes/Sage/readme.txt <<README
Drag Sage to your Applications folder

Starting Sage from the command line is also possible if you create
a link to it on your path. For example:

sudo ln -s /Applications/ /usr/local/bin/sage

(you must double-click Sage once to run it before sageMac.command is created)
hdiutil eject /Volumes/Sage
hdiutil convert -format UDZO Sage.dmg -o Sage-${version}-${platform}.dmg
rm -f Sage.dmg

When this completes, you will have a typical Mac program disk image (Sage-2.10.1-10.5intel.dmg, 210 MB) that is ready to distribute.

The sage.icns and files are attached to this page. These are the same files and instructions attached to [ Ticket #1731] on the Sage Issue tacker.

Another method of creating a Mac Application is to use the freeware (though not currently free as in speech) application [ Fluid] to create a Site Specific Browser (which I call This has the advantage that Sage will be a separate application. Similar things could probably be achieved with [ Prism], but I wanted a tighter integration with OS X, and I don't really like Firefox.

To do this you must download Fluid and create a new browser pointing to http://localhost:8000/. You can now use your site specific browser to access the sage notebook, but it's still not ideal in the sense that you must start the sage server before opening To work around this you can replace the executable in with a script which launches the sage server and then opens the application. For example I used the following simple shell script after having moved to I made it use an insecure notebook, since that is simpler and probably acceptable on a single user machine (correct me if I am wrong).

# TODO: check here for environment variables that might indicate where
# a user-installed version of sage is

# sage doesn't handle /../ well, so we eliminate them here
PACKAGE_DIR=$(echo $BASH_SOURCE | grep -o '.*\.app')



# TODO: must empty the log or something
curl localhost:8000 > /dev/null 2> /dev/null
if [ $? != 52 -a $? != 0 ]; then
    # This should probably be improved upon some
    "$SAGE_BIN" -c "notebook(open_viewer=False, secure=false)" >/dev/null &

# Stall until the server has started.  If there is a problem this will loop forever... 
curl localhost:8000 >/dev/null 2>/dev/null
while [ $? != 52 -a $? != 0 ]; do
    sleep 1
    curl localhost:8000 >/dev/null 2>/dev/null


I am not sure of the legality of distributing a pre-packaged version, since Fluid is not open source and the GPL is very restrictive, but I would like to put up a pre-packaged version after I sort that out.