Skip to content

Instantly share code, notes, and snippets.

@dmerand
Last active April 21, 2017 23:59
Show Gist options
  • Save dmerand/25a144a20a32cfb7ea246f9850fdef58 to your computer and use it in GitHub Desktop.
Save dmerand/25a144a20a32cfb7ea246f9850fdef58 to your computer and use it in GitHub Desktop.
Shell Script FileMaker DB Launcher
#!/usr/bin/env sh
# FileMaker Script Launcher
# =========================
#
# **Author:** Donald L. Merand
#
# General template to run ANY FileMaker script.
# NOTE: This is probably Mac-only. I haven't tested it on other platforms.
# Utility to url-encode a string. Could be cleaner than this.
url_encode()
{
echo $(/usr/bin/env ruby -e "require 'erb'; include ERB::Util; puts url_encode('$1')")
}
# Show the help screen
show_help()
{
cat <<HELP
FILEMAKER SCRIPT LAUNCHER
Usage - \`launcher <options>\`
Options:
-h - Show this help screen
-u - User name
-p - Password
-s - Database server (eg. test.database.org)
-d - Database
-r - Script Name (optional)
-m - Parameter (optional)
HELP
}
# Default variables
USER="yourusername"
PASS="yourpasswordgoeshere"
SERVER="server.example.com"
DATABASE="db_to_open"
SCRIPT="scriptname"
PARAM="params_if_any"
# get script options
while getopts ":hu:p:s:d:r:m" OPTNAME
do
case "$OPTNAME" in
"h")
show_help
exit
;;
"u")
USER=$(url_encode "${OPTARG}")
;;
"p")
PASS=$(url_encode "${OPTARG}")
;;
"s")
SERVER="${OPTARG}"
;;
"d")
DATABASE=$(url_encode "${OPTARG}")
;;
"r")
SCRIPT=$(url_encode "${OPTARG}")
;;
"m")
PARAM=$(url_encode "${OPTARG}")
;;
"?")
echo "Unknown option $OPTARG"
;;
":")
echo "No argument value for option $OPTARG"
;;
*)
# Should not occur
echo "Unknown error while processing options"
;;
esac
done
# Param check
if [ -z ${USER} -o -z ${SERVER} ]; then
show_help
exit
fi
if [ -z ${DATABASE} ]; then
show_help
exit
fi
# Setup
if [ -z ${SCRIPT} ]; then
URLSCRIPT=""
else
URLSCRIPT="?script=${SCRIPT}"
fi
if [ -z ${PARAM} ]; then
URLPARAM=""
else
URLPARAM="&param=${PARAM}"
fi
# Do the actual work
echo opening "fmp://${USER}:${PASS}@${SERVER}/${DATABASE}${URLSCRIPT}${URLPARAM}"
/usr/bin/open "fmp://${USER}:${PASS}@${SERVER}/${DATABASE}${URLSCRIPT}${URLPARAM}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment