Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Recursive script to find all WMF and EMF in the custom dir and subs, then convert to PNG 300 dpi using Universal Office Converter and ImageMagick.
- cd ~/Works/Results/PXRD/
- var1=$(find . -type f -name '*.?mf' | wc -l)
- var2=$(find . -type f -name '*.png' | wc -l)
- var3=$(find . -type f -name '*_Pattern.png' | wc -l)
- var4=$(($var2 - $var3))
- if [ $var1 -ne $var4 ]; then
- if [ -z "$(pidof soffice.bin)" ]; then
- unoconv --listener &
- echo "$(tput setaf 5)Universal Office Converter loading, please wait...$(tput sgr 0)"
- sleep 20
- tmpdir="$(mktemp -d)"
- elif [[ -n $(ps ax | grep -v grep | grep StarOffice) ]]; then
- echo "$(tput setaf 5)Universal Office Converter is already running.$(tput sgr 0)"
- else
- echo "$(tput setaf 1)LibreOffice is already running. Please exit and try again.$(tput sgr 0)"
- exit
- fi
- else
- echo "$(tput setaf 1)Files not found.$(tput sgr 0)"
- exit
- fi
- for i in **/*.?mf; do
- if [ ! -f "${i%?mf}png" ]; then
- j="${i##*/}"
- echo "$(tput setaf 6)Converting to pdf [ $j ]$(tput sgr 0)"
- unoconv -f pdf -o "$tmpdir/${j%?mf}pdf" "$i"
- echo "$(tput setaf 2)Converting to png [ ${j%?mf}pdf ]$(tput sgr 0)"
- j="${j%?mf}pdf"
- i="${i%?mf}pdf"
- convert -density 300 -trim -bordercolor white -border 5 "$tmpdir/$j" "${i%pdf}png"
- fi
- done
- echo "$(tput setaf 3)Cleaning temporary files$(tput sgr 0)"
- rm -rf -- "$tmpdir"
- if [[ -n $(ps ax | grep -v grep | grep StarOffice) ]]; then
- pkill -15 soffice
- echo "$(tput setaf 5)Aloha.$(tput sgr 0)"
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement