Mac-like application for Sage on Mac

11 views
Skip to first unread message

rpmu...@gmail.com

unread,
Feb 8, 2008, 9:20:32 PM2/8/08
to sage-devel
I remember reading somewhere when I downloaded a version of Sage that
the program was soliciting help from mac-experts in making the binary
version of Sage a little more mac-like.

I'm certainly not a mac expert. However, I got Sage working through a
mac-like icon using the Platypus program (http://www.sveinbjorn.org/
platypus). There's a good article here (http://www.tuaw.com/2007/05/08/
platypus-create-mac-binaries-from-ruby-perl-shell-scripts-et/) about
how to use the program here. But it's kinda nice. Among other
programs, the Gimp.app program uses Sage for it's Mac application
bundle.

I created a shell script that looks like this:

#!/bin/sh
cat > startsage << EOF
notebook()
EOF
/Users/rmuller/Programs/sage-2.10/sage < sage

and had Platypus run it, putting the output into a text window. This
runs the notebook() function and the twisted server, and pops open the
browser with the Sage notebook.

The drawback is that the script needs to know the path to my sage
installation. I think that the workaround to this is to actually put
the entire Sage installation in the folder that Platypus creates for
the application. OS X applications on the Mac are actually folders
(unix directories).

Does this sound like it would be useful to the Sage community if I
could get it working?

mabshoff

unread,
Feb 10, 2008, 5:41:08 AM2/10/08
to sage-devel


On Feb 9, 3:20 am, "rpmul...@gmail.com" <rpmul...@gmail.com> wrote:

Hi,

> I remember reading somewhere when I downloaded a version of Sage that
> the program was soliciting help from mac-experts in making the binary
> version of Sage a little more mac-like.

Sure, that is certainly a goal.

> I'm certainly not a mac expert. However, I got Sage working through a
> mac-like icon using the Platypus program (http://www.sveinbjorn.org/
> platypus). There's a good article here (http://www.tuaw.com/2007/05/08/
> platypus-create-mac-binaries-from-ruby-perl-shell-scripts-et/) about
> how to use the program here. But it's kinda nice. Among other
> programs, the Gimp.app program uses Sage for it's Mac application
> bundle.
>
> I created a shell script that looks like this:
>
> #!/bin/sh
> cat > startsage << EOF
> notebook()
> EOF
> /Users/rmuller/Programs/sage-2.10/sage < sage
>
> and had Platypus run it, putting the output into a text window. This
> runs the notebook() function and the twisted server, and pops open the
> browser with the Sage notebook.
>
> The drawback is that the script needs to know the path to my sage
> installation. I think that the workaround to this is to actually put
> the entire Sage installation in the folder that Platypus creates for
> the application. OS X applications on the Mac are actually folders
> (unix directories).

Hard coding the path of the Sage location is certainly a problem,
which might be solved in the way you suggested above.


> Does this sound like it would be useful to the Sage community if I
> could get it working?

Sure, I have added your info to http://trac.sagemath.org/sage_trac/ticket/1731
- please let us know if you need any kind of technical input from our
end. The creation of those applications needs to be scripted without
the need of human interaction since creating them any other way would
make it real work and potentially break them due to human error.

Cheers,

Michael

Robert Bradshaw

unread,
Feb 11, 2008, 8:59:35 PM2/11/08
to sage-...@googlegroups.com
Is this related to the .app bundle that showed up on sage-devel a
month or so ago?

- Robert

Ivan Andrus

unread,
Feb 11, 2008, 10:43:49 PM2/11/08
to sage-...@googlegroups.com
> I'm certainly not a mac expert. However, I got Sage working through a
> mac-like icon using the Platypus program (http://www.sveinbjorn.org/
> platypus). There's a good article here (http://www.tuaw.com/
> 2007/05/08/
> platypus-create-mac-binaries-from-ruby-perl-shell-scripts-et/) about
> how to use the program here. But it's kinda nice. Among other
> programs, the Gimp.app program uses Sage for it's Mac application
> bundle.
>
> and had Platypus run it, putting the output into a text window. This
> runs the notebook() function and the twisted server, and pops open the
> browser with the Sage notebook.

I have actually taken a slightly different approach, in that I used
Fluid.app <http://fluidapp.com/> to create a site specific browser
that also starts Sage. This means that Sage is a "real application"
that I can Cmd-Tab between etc. Can Platypus does this? If not it
probably could (I may look into it). Frankly, I hate using Sage in a
browser, because it is mixed in with all my other browser windows.
For me a separate application is the only acceptable long-term solution.

There are a few problems with my Fluid-based app currently. One is
that Fluid tacks on '.com' to the URL for local addresses. That
certainly means it's not ready to be released to end users. There is
also a certificate issue, but I assumed that was my fault for running
the sage server wrong. There is also a potential licensing issue.
Fluid is closed source, and I don't know how applications built with
it can be distributed.

If you are interested I would be more that happy to tell you more/send
you what I have. It's at a very early stage and I haven't worked out
the problems, but since you brought it up, I thought I would mention
what I have done.

> The drawback is that the script needs to know the path to my sage
> installation. I think that the workaround to this is to actually put
> the entire Sage installation in the folder that Platypus creates for
> the application. OS X applications on the Mac are actually folders
> (unix directories).

That's the solution that I was considering as well. We could just
distribute binary versions as regular applications. The only
(potential) problem that I see it that notebooks should be stored in
some place that will be saved across upgrades/new installs. This
shouldn't be hard to fix though.

> Does this sound like it would be useful to the Sage community if I
> could get it working?


+1

-Ivan Andrus

Yi Qiang

unread,
Feb 12, 2008, 12:06:58 AM2/12/08
to sage-...@googlegroups.com
Ivan,
I think the Fluid idea is brilliant! I've actually used it before and never thought to use it with SAGE. Can you post instructions on how you set it up?

Cheers,
Yi

http://yiqiang.org   

Franco Saliola

unread,
Feb 12, 2008, 12:08:09 PM2/12/08
to sage-...@googlegroups.com
On Feb 8, 2008 9:20 PM, rpmu...@gmail.com <rpmu...@gmail.com> wrote:

> I'm certainly not a mac expert. However, I got Sage working through a
> mac-like icon using the Platypus program (http://www.sveinbjorn.org/
> platypus).

I'm not sure what Platypus is (I haven't clicked on the link), but
here is what I've got set up.

I created the following Apple Script; I bundled it as a .app; changed
the icon to the sage logo from sagemath.org; tossed it into my sage
directory. I'll attach the files, and there are some notes below.

tell application "Finder"
open document file "sage" of folder of (path to me) using application
file "Terminal.app" of folder "Utilities" of folder "Applications" of
startup disk
end tell

Notes:

1. This does NOT depend on the location of the sage directory on the
hard drive. (It does depend on the location of Terminal.app, but
that's standard on Mac OS X.)

2. It just starts sage in the terminal, not the notebook. The use
needs to use notebook(). But this is what I preferred. The Apple
Script can point to a secondary sage-notebook bash script that checks
for a running sage notebook instance or starts one if it doesn't
exist.

Take care,
Franco

--

sage.app
sage.scpt

rpmu...@gmail.com

unread,
Feb 12, 2008, 6:24:19 PM2/12/08
to sage-devel
Fluid is indeed a great idea! I hadn't thought of it, in part because
I'm still running Mac OS 10.4 until my employer authorizes 10.5. Fluid
only works with 10.5.

Platypus is a program that builds an app bundle for little scripts. I
used it to wrap a simple bash shell wrapper for Sage, and have used it
for other backup scripts and the like. The website seems to be down,
but, in the meantime, there's a good article here:
http://www.tuaw.com/2007/05/08/platypus-create-mac-binaries-from-ruby-perl-shell-scripts-et/

Ivan Andrus

unread,
Feb 12, 2008, 10:30:12 PM2/12/08
to sage-...@googlegroups.com
> I think the Fluid idea is brilliant! I've actually used it before
> and never thought to use it with SAGE. Can you post instructions on
> how you set it up?

Create an application (hereafter referred to as Sage.app) pointing to
https://localhost:8000/
or
http://localhost:8000/
I don't know if there is a problem running in non-secure mode on your
own machine, but if you run in secure mode there may be an issue in
which the Fluid app appears to do nothing. This is probably due to a
certificate issue, but if you tell Safari to always accept it, it
seems to work ok.

Then find Sage.app in the Finder. Ctrl-click and "Show Package
Contents"
Goto Contents/MacOS.
Rename FluidInstance to FluidInstance.bin
Create a file called FluidInstance which contains the following script

#!/bin/bash

#path to sage
SAGE_EXE=/Users/gvol/Desktop/sage-2.9.2/sage

# check if sage is running on port 8000
curl localhost:8000 > /dev/null 2> /dev/null
if [ $? != 52 -o $? != 0 ]; then
# start sage if we need to. This could be made to run in non-secure
mode etc.
$SAGE_EXE -notebook 2>&1 > sage.log &
fi

# execute the 'real' Fluid application
exec $BASH_SOURCE.bin

# end script


Set the permissions to be executable. I'm not sure how to do this in
the Finder, but it can be done from the Terminal by
chmod +x /path/to/FluidInstance
You can get the path by dragging the file from the Finder to a
Terminal window.

You will of course have to substitute the path to sage in the script.

This is the script that I used, so I know it works, but I think I
prefer something a little more like rpmuller used would be
preferable. For one thing, I never stop the server (though this is
what I prefer).

It seems like sometimes, if the server isn't already started, then it
opens the window too soon, and can't connect. If it can't connect
then it gives up trying ever again until I quit and restart. So it's
far from perfect.

I would also be willing to put together an all-in-one version that
contains the sage tree within Sage.app. This would be extremely
simple to create for each new build in an automated way.

I also am planning to look into adding an HTML window to Platypus
since I think that would be preferable in many ways, and feels less
hackish to me.

HTH,
Ivan

Reply all
Reply to author
Forward
0 new messages