Differences between revisions 1 and 3 (spanning 2 versions)
Revision 1 as of 2008-02-12 23:37:10
Size: 526
Editor: TedWright
Comment:
Revision 3 as of 2008-02-13 00:10:08
Size: 4180
Editor: TedWright
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
The [http://www.sveinbjorn.org/platypus Platypus] program is used to make things easier. Download ''Platypus'', and install it along with its command line tools. Using the command line Platypus program makes this process scriptable. The [http://www.sveinbjorn.org/platypus 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.
Line 6: Line 6:

Next, a small Python program called ''sageMac.py'' is useful to set things up. This program will create a ''.command'' file so that OS X will start Sage in the Terminal.app 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 ''sageMac.py'':

{{{#!python
import sys, commands, string, os

# path to inside of Sage.app
appname = string.join(string.split(sys.argv[0], '/')[:-3], '/')
sageDir = appname + '/Contents/Resources/sage'
sageScriptOrig = sageDir + '/sage'
sageScriptNew = sageDir + '/sageMac.command'

# copy Sage startup script to end in .command so that OS X will launch it
commands.getoutput('cp -f %s %s' % (sageScriptOrig, sageScriptNew))

# edit sageScriptNew to reflect current location (sageDir)
f = open(sageScriptNew)
lines = f.read()
f.close()

splitLines = string.split(lines, '"')
newLines = [splitLines[0], sageDir]
newLines.extend(splitLines[2:])
newLines = string.join(newLines, '"')

f = open(sageScriptNew, 'w')
f.write(newLines)
f.close()

# run the script
os.execl('/usr/bin/open', '/usr/bin/open', sageScriptNew)
}}}

With ''sage.icns'', ''sageMac.py'', 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 sageMac.py Sage.app
}}}

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 ''Sage.app'' 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/Sage.app/Contents/Resources/sage/sageMac.command /usr/local/bin/sage
}}}

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

Finally, the Sage.app 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 Sage.app /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/Sage.app/Contents/Resources/sage/sageMac.command /usr/local/bin/sage

(you must double-click Sage once to run it before sageMac.command is created)
README
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 ''sageMac.py'' files are attached to this page. These are the same files and instructions attached to [http://trac.sagemath.org/sage_trac/ticket/1731 Ticket #1731] on the Sage Issue tacker.

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

The [http://www.sveinbjorn.org/platypus 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 sageMac.py is useful to set things up. This program will create a .command file so that OS X will start Sage in the Terminal.app 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 sageMac.py:

   1 import sys, commands, string, os
   2 
   3 # path to inside of Sage.app
   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'
   8 
   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))
  11 
  12 # edit sageScriptNew to reflect current location (sageDir)
  13 f = open(sageScriptNew)
  14 lines = f.read()
  15 f.close()
  16 
  17 splitLines = string.split(lines, '"')
  18 newLines = [splitLines[0], sageDir]
  19 newLines.extend(splitLines[2:])
  20 newLines = string.join(newLines, '"')
  21 
  22 f = open(sageScriptNew, 'w')
  23 f.write(newLines)
  24 f.close()
  25 
  26 # run the script
  27 os.execl('/usr/bin/open', '/usr/bin/open', sageScriptNew)

With sage.icns, sageMac.py, 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 sageMac.py Sage.app

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 Sage.app 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/Sage.app/Contents/Resources/sage/sageMac.command /usr/local/bin/sage

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

Finally, the Sage.app 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 Sage.app /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/Sage.app/Contents/Resources/sage/sageMac.command /usr/local/bin/sage

(you must double-click Sage once to run it before sageMac.command is created)
README
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 sageMac.py files are attached to this page. These are the same files and instructions attached to [http://trac.sagemath.org/sage_trac/ticket/1731 Ticket #1731] on the Sage Issue tacker.