Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
#!/bin/bash
#!/bin/bash -x
# OpenSCAD.sh - Utility script to Launch OpenSCAD
#
# Tested on macOS mostly
#
# USAGE
#
# With no arguments, launches app.
#
# ./scripts/OpenSCAD.sh
#
# Passes arguments to app, pruning any .scad or .stl to a single one
#
# ./scripts/OpenSCAD.sh webcam_small_mount/webcam_base_bracket.scad
#
# from top-level of psychic-winner directory:
# open --new -a /Applications/OpenSCAD.app --env OPENSCADPATH=`pwd`/libraries
#CURRENT_DIR="${PWD}"
LOCAL_TOP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && cd ../ && pwd )"
LOCAL_LIBRARIES_DIR=$( cd "${LOCAL_TOP_DIR}"/libraries/ && pwd )
# echo "$CURRENT_DIR"
# echo "$LOCAL_TOP_DIR"
# echo "$LOCAL_LIBRARIES_DIR"
# Darwin / Linux
os_name="$(uname -s)"
DEFAULT_LIBRARIES_DIR_macos="$HOME/Documents/OpenSCAD/libraries"
DEFAULT_LIBRARIES_DIR_linux="$HOME/.local/share/OpenSCAD/libraries"
app_linux="openscad" # TODO: add openscad-nightly as a fall-thru
app_path_linux="$(type -P $app_linux)"
app_path_linux_retval=$?
if [ "$(uname -s)" == 'Linux' ] && [ $app_path_linux_retval -ne 0 ] ; then
echo "ERROR: 'openscad' not found"
exit 1
fi
app_macos="OpenSCAD.app"
app_path_macos="/Applications/${app_macos}"
case $os_name in
Darwin*)
DEFAULT_LIBRARIES_DIR="${DEFAULT_LIBRARIES_DIR_macos}"
app_path="${app_path_macos}"
app_bin="${app_path}"/Contents/MacOS/OpenSCAD
;;
*)
DEFAULT_LIBRARIES_DIR="${DEFAULT_LIBRARIES_DIR_linux}"
app_path="${app_path_linux}"
app_bin="${app_path}"
;;
esac
# exports (also be explicit below)
export OPENSCADPATH="$LOCAL_LIBRARIES_DIR:$DEFAULT_LIBRARIES_DIR"
# echo app_path=$app_path
# echo app_bin=$app_bin
# determine if there are any arguments on command line
if [ -z "${1}" ]
then
echo OPENSCADPATH="$OPENSCADPATH"
# There are no arguments, so
case $os_name in
Darwin*)
echo Starting "$app_path"...
open -a "${app_path}" --env OPENSCADPATH="$OPENSCADPATH"
;;
*)
set -o xtrace
OPENSCADPATH="$OPENSCADPATH" "${app_bin}"
;;
esac
else
# There are arguments, so tell openscad about them
myArgs=( )
scad_file=""
for arg in "${@}" ; do
case "$arg" in
*.scad)
bn=$(basename "$arg")
dir="$( cd "$( dirname "$arg" )" && pwd )"
#echo "$dir/$bn"
# only keep last .scad argument if there's more than one
scad_file="$dir/$bn"
;;
*.stl) # will open by creating Untitled.scad with an import
bn=$(basename "$arg")
dir="$( cd "$( dirname "$arg" )" && pwd )"
#echo "$dir/$bn"
# only keep last .scad/.stl argument if there's more than one
scad_file="$dir/$bn"
;;
-dotscad) # add dotSCAD main directory to path also
dotscad_dir="${LOCAL_LIBRARIES_DIR}/dotSCAD/src"
if [ -d "${dotscad_dir}" ] ; then
export OPENSCADPATH="${dotscad_dir}:${OPENSCADPATH}"
else
echo "ERROR: '-dotscad' specified but ${dotscad_dir} not found"
exit 1
fi
;;
*)
echo forwarding argument "'$arg'"
myArgs+=("$arg")
;;
esac
done
if [[ -n $scad_file ]] ; then
#echo $scad_file
myArgs=("${myArgs[@]}" "$scad_file")
fi
echo Using args: "${myArgs[@]}"
echo OPENSCADPATH="$OPENSCADPATH"
case $os_name in
Darwin*)
# opens new app (if already running) and waits for app to exit
open -n -W -a "${app_path}" --env OPENSCADPATH="$OPENSCADPATH" --args "${myArgs[@]}" &
# can view stdout/stderr running binary directly like this:
# "${app_bin}" "${myArgs[@]}"
;;
*)
set -o xtrace
OPENSCADPATH=$OPENSCADPATH "${app_bin}" "${myArgs[@]}"
;;
esac
fi
4951fc2d1This file is pinned to the selected release. Download the original to open it in your design tool.