Page 1 of 1

Running KnotPlot effectively on a Mac

PostPosted: Wed May 13, 2009 11:30 pm
by rob

Because KnotPlot is not a native Mac application, but ported from Windows, it has a number of oddities that take some getting used to. These are likely to annoy Apple enthusiasts, but once you've done a bit of setup, everything should be fine.

There are a few things to note for running KnotPlot on a Mac:
  • KnotPlot by default saves into the folder where the KnotPlot application (the orange and blue knot icon) resides. because of this, it's generally best not to put the KnotPlot application into your /Applications folder. You don't want KnotPlot to be saving to that folder because it will quickly become cluttered with non-applications. Instead put KnotPlot into its own folder. A good place might be a KnotPlot folder inside of /Applications. So, inside of /Applications/KnotPlot you would see the orange & blue KnotPlot application icon.
  • it's best to create new folders (directories) for each project you're working on. that way things will remain uncluttered. if you start KnotPlot by double clicking the application icon, things will only get read from or saved into the folder where the KnotPlot application resides. That's not what we want. Instead, we start KnotPlot in a different way. here is what to do:
    • open a Terminal application (you should find Terminal in /Applications or /Applications/Utilities, i can't quite remember)
    • in the Terminal shell window, change directory (cd) to your project directory
    • start KnotPlot from the command line, with an command line flag requesting to keep the same directory when reading and writing files:

      /Applications/KnotPlot/ -keepdir

      This is assuming you put KnotPlot in its own folder within /Applications. if you put it someplace else, modify accordingly (see the p.p.s. below). With the -keepdir flag, KnotPlot will read from and write into whatever directory you ran the above command in.
    • because it can be quite tedious to enter the above command each time you want to run KnotPlot, edit you bash or tcsh resource file and make an alias. if your shell is the tcsh, you would put something like this into your ~/.cshrc file:

      alias knotplot "/Applications/KnotPlot/ -keepdir \!* &"

      Then, from any Terminal command line in any directory, you can start KnotPlot by simply typing
      and all file read/writes will stay within that directory.
      The \!* in the alias allows you to add extra command line flags if you want to start KnotPlot in a non-traditional manner, for example;
      knotplot -nog
      to start KnotPlot in non-graphics mode, or:
      knotplot -sstereo
      for something completely different.
      The & in the alias definition simply runs KnotPlot in the background so you can continue to enter commands into the Terminal shell you started KnotPlot from.

      The alias above is for the tcsh. If you are running the bash or some other shell, there is something equivalent.

Now, how to write and run scripts. Don't copy the script from somewhere and paste it into the KnotPlot command window. Instead, do this:
  • put your script into a plain text file, for example myscript.txt or myscript.kps. I generally give most of my KnotPlot scripts a .kps file extension, but that's completely arbitrary (they're just plain text files). put your script file in the directory you're working in.
    Edit your script files with TextEdit as plain text. Don't use a word processor. make sure you save them as plain (or raw) text.
  • use either function key binding, aliases or custom DemoA or DemoB panels to run your scripts quickly and easily. For example, you can bind a function key to run a script whenever you press the F1 key:

    function 1 <myscript.txt

    (enter this into the KnotPlot command window).
    You can bind a function key to run any KnotPlot command. This one happens to run the command <myscript.txt which says to load and exectute the script myscript.txt (that's what the angle bracket does)
  • use the knotplotrc.kps file to put your function key definitions so that you don't have to retype them every time you start KnotPlot. This file should be located in the directory where you are planning to start KnotPlot from. It's just a list of KnotPlot commands that will be executed upon KnotPlot startup. The advantage of putting different projects into different directories is that you can have a custom knotplotrc.kps startup script for each project
  • you don't need to bind to a function key, you can run your script directly by typing
    into the KnotPlot Command Window
  • once you have your script bound to a function key, you can edit the script in Textedit, make modifications and save it, then press your function key in KnotPlot to execute your newly modified script. This makes it very easy to interactively refine a script to make it do what you want.

Don't forget there is a manual. It's out of date and wrong in some cases, but many of the basic commands work as described. Here are a few recommendations:
The PDF manual located at is less out of date than the HTML version, so you might want to look at that.

Please post your questions here if you run into problems. KnotPlot can be tedious in some ways, but it not that tedious. :)

hope this helps,

p.s. for Windows users, please look in the projects folder within the KnotPlot installation folder and read the README file found there. This gives you instructions how to create custom project directories.

p.p.s. in case you put the KnotPlot application some place else, here is the general rule for determining what you should run from the command line.

where THEFOLDERNAME is replaced with whatever folder (directory) contains KnotPlot. For example, if you have the KnotPlot application sitting on your Desktop, then you would enter
~/Desktop/ -keepdir
(but remember to make an alias anyway so you don't have to keep on retyping this long command line)

Re: Running KnotPlot effectively on a Mac

PostPosted: Mon Aug 30, 2010 9:10 pm
by rob
To make things slightly simpler, you can follow these steps:
  • copy and paste the following into a new file named knotplot
    Code: Select all
    #!/bin/tcsh -f

    set KP =

    foreach KP_exe ($HOME/Desktop/$KP $HOME/Desktop/KnotPlot/$KP /Applications/$KP /Applications/KnotPlot/$KP)
      if (-e $KP_exe) then
        $KP_exe -keepdir $*

    echo "can't find KnotPlot application, it should be in one of the following locations:"
    echo $HOME/Desktop $HOME/Desktop/KnotPlot /Applications /Applications/KnotPlot
  • put this new file called knotplot into a directory that is in your path. A good choice might be /usr/local/bin
    Make sure the file is executable, type in something like
    chmod +x knotplot
    into a Terminal shell.
  • start up a new Terminal session and change directory to a newly created working directory or something you have from earlier.
  • don't start KnotPlot by double-clicking the application icon, instead start by entering the following into the Terminal shell:
    This will have the effect of starting KnotPlot with your project directory being the working directory. So anything you create in KnotPlot will be saved there.