Last active
October 31, 2018 05:01
-
-
Save ymkjp/146206e0cf56052b7759589df4de5f98 to your computer and use it in GitHub Desktop.
A script to extract images from XLSX file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Alfred PowerPack users: eximage.alfredworkflow