Skip to content

Instantly share code, notes, and snippets.

@ymkjp
Last active October 31, 2018 05:01
Show Gist options
  • Save ymkjp/146206e0cf56052b7759589df4de5f98 to your computer and use it in GitHub Desktop.
Save ymkjp/146206e0cf56052b7759589df4de5f98 to your computer and use it in GitHub Desktop.
A script to extract images from XLSX file
#!/bin/bash
# A script to extract images from XLSX file
# Usage:
# chmod u+x ./eximage.sh
# bash ./eximage.sh __PATH_TO_FILE__
SCRIPT_NAME="$(basename ${0})"
TARGET_PATH="${1}"
TARGET_FILENAME="$(basename ${TARGET_PATH})"
TARGET_EXTENSION="${TARGET_FILENAME##*.}"
printError() {
echo "[${SCRIPT_NAME}] ERROR: ${@:=Something went wrong.}" 1>&2
}
if [[ -x "$(command -v unzip)" ]]; then
printError "The command 'unzip' is not available."
elif [[ ! -r "${TARGET_PATH}" || "${TARGET_EXTENSION}" != "xlsx" ]]; then
printError "The target file '${TARGET_PATH}' must be readable XLSX file."
fi
OPEN_PATH="${2:=xl/media}"
DST_DIR="${TMPDIR:=/var/tmp}/${SCRIPT_NAME}/$(date +%s)_${TARGET_FILENAME%.*}"
TMP_FILE="${DST_DIR}/${TARGET_FILENAME}.zip"
mkdir -p "${DST_DIR}" && cp "${TARGET_PATH}" "${TMP_FILE}" && unzip "${TMP_FILE}" -d "${DST_DIR}"
[[ -x "$(command -v open)" ]] && open "${DST_DIR}/${OPEN_PATH}"
@ymkjp
Copy link
Author

ymkjp commented Oct 31, 2018

@ymkjp
Copy link
Author

ymkjp commented Oct 31, 2018

For Alfred PowerPack users: eximage.alfredworkflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment