Created
November 26, 2023 09:05
-
-
Save isurfer21/b447062fa2fe00dee118b1f92a59f03d to your computer and use it in GitHub Desktop.
Libre Office file convertor CLI for macOS
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/zsh | |
while getopts ":f:" opt; do | |
case ${opt} in | |
f ) | |
file=$OPTARG | |
;; | |
\? ) | |
echo "Invalid option: -$OPTARG" 1>&2 | |
exit 1 | |
;; | |
: ) | |
echo "Invalid option: -$OPTARG requires an argument" 1>&2 | |
exit 1 | |
;; | |
esac | |
done | |
shift $((OPTIND -1)) | |
if [ -z "$file" ]; then | |
echo "Usage: ${0##*/} [-f file] {pdf|epub|html|text|odp|odt}" >&2 | |
exit 1 | |
fi | |
soffice=/Applications/LibreOffice.app/Contents/MacOS/soffice | |
case "$1" in | |
pdf) | |
$soffice --headless --invisible --convert-to pdf $file | |
;; | |
epub) | |
$soffice --headless --invisible --convert-to epub $file | |
;; | |
html) | |
$soffice --headless --invisible --convert-to "html:XHTML Writer File:UTF8" $file | |
;; | |
txt) | |
$soffice --headless --invisible --convert-to "txt:Text (encoded):UTF8" $file | |
;; | |
odp) | |
$soffice --headless --invisible --convert-to odp $file | |
;; | |
odt) | |
$soffice --headless --invisible --convert-to odt $file | |
;; | |
*) | |
echo "Invalid option: $1" >&2 | |
echo "Usage: $0 [-f file] {pdf|epub|html|text|odp|odt}" >&2 | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment