#!/bin/bash # NAME: # imagej # # PURPOSE: # This bash script offers a user-friendly command-line wrapper for # the ImageJ program running under Mac OS X. The ImageJ folder # distributed by the NIH must be located in the Applications folder # on your Mac for the script to be used as is. # # MODIFICATION HISTORY: # Written by Carl Salvaggio # January, 2013 Original Code # # DISCLAIMER: # This source code is provided "as is" and without warranties as to # performance or merchantability. The author and/or distributors of # this source code may have made statements about this source code. # Any such statements do not constitute warranties and shall not be # relied on by the user in deciding whether to use this source code. # # This source code is provided without any express or implied warranties # whatsoever. Because of the diversity of conditions and hardware under # which this source code may be used, no warranty of fitness for a # particular purpose is offered. The user is advised to test the source # code thoroughly before relying on it. The user must assume the entire # risk of using the source code. function print_usage { echo "" echo "Usage: imagej [-v -h -b -p port_number] [image_filename]" echo "" echo " Launches the ImageJ graphical interface from the command line" echo "" echo " Options:" echo " -v" echo " verbose/debug mode [do not launch ImageJ]" echo " -h" echo " help [print this usage message]" echo " -b" echo " run ImageJ in the background" echo " -p port_number" echo " specify the port ImageJ uses to determine if" echo " another instance is running; if an instance" echo " is already running on that port, join that" echo " instance, if not, create a new instance [the" echo " default is 1]" echo "" echo " NOTE: specifying a port of 0 does not check for" echo " another instance and just creates a new one" echo "" } OPTIND=1 verbose=0 background=0 port="1" while getopts "vhbp:" opt; do case "$opt" in v) verbose=1 ;; h) print_usage exit 0 ;; b) background=1 ;; p) port=$OPTARG ;; esac done shift $((OPTIND-1)) [ "$1" = "--" ] && shift cmd="java -jar -Xmx1024m /Applications/ImageJ/ImageJ64.app/Contents/Resources/Java/ij.jar -ijpath /Applications/ImageJ" cmd="$cmd -port$port" image_filename=$@ if [ -f $image_filename ]; then cmd="$cmd $image_filename" else if [ -n $image_filename ]; then echo "imagej: Specified image file does not exist" exit 1 fi fi if [ $verbose -eq 1 ]; then echo "DEBUG DISPLAY" echo " verbose = $verbose" echo " background = $background" echo " port = $port" echo " image_filename = $image_filename" echo "COMMAND" echo " $cmd" else if [ $background -eq 1 ]; then $cmd & else $cmd fi fi exit 0