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:

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.