With all the great new nightly builds for Slicer, the installed executables obviously reside in different folders for different versions (e.g. %PROGRAMFILES%\Slicer 4.7.0-2017-07-22\Slicer.exe). I think it would be a good idea to add an option “Change SLICERPATH environment variable” to the highlighted portion of the installation program so that the user’s custom shortcuts that use Slicer.exe don’t have to be changed every time they install a newer version of Slicer.
This is what it currently is now, where the user has to change the target every time they install Slicer.exe to a different folder (i.e. new version of Slicer):
What we envision for this is that extension would create the shortcut for itself. For example, when you install your module, it could show a “Pin to Start menu” button, which would create the shortcut to the appropriate Slicer version.
We haven’t implemented this in any modules yet, but we would be very interested and can give you any help you need.
The reason I am suggesting this is because some users (including myself and labmates) use Python scripts without the use of a custom extension, such as this script. To utilize the script, the user can just add a shortcut linking to Slicer.exe and using the --python-script argument. With an environment variable pointing to Slicer’s program path, it would be very convenient for the script users.
A global environment variable could be easily corrupted unintentionally (just by some one installing or uninstalling a new Slicer version could break things). So, automatic creation and update of such a variable does not seem feasible in general, but if you don’t particularly care which Slicer version you will find, then you can use file association information, which defines what program to use to open Slicer scene files (.mrml and .mrb), which is typically the version that you installed last time.
So, to run a Python script from .bat file you can do this:
@echo off
REM Get Slicer executable in SlicerExecutable environment variable
for /f "delims== tokens=2" %%a in ('ftype Slicer') do set SlicerExecutable=%%a
set SlicerExecutable=%SlicerExecutable:~0,-5%
REM Start a Python script in Slicer
%SlicerExecutable% --python-code "print('It works!')"
On Windows, recent Slicer Preview Releases (Slicer-4.13) registers the Slicer application during install. This makes it possible to use start command to launch Slicer. For example, this command on the command-line starts Slicer and loads an image: