Skip to content

Instantly share code, notes, and snippets.

@tiriana
Created January 30, 2024 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiriana/6f9b8fa7861592e3ac0c2271de502f46 to your computer and use it in GitHub Desktop.
Save tiriana/6f9b8fa7861592e3ac0c2271de502f46 to your computer and use it in GitHub Desktop.
Auto-Open Office Script: Watch & Open New Spreadsheet Files in Downloads
#!/bin/bash
# This script monitors the Downloads folder for new .xlsx, .csv, and .xls files.
# When a new file is detected, it:
# 1. Closes all running instances of OpenOffice/LibreOffice Calc.
# 2. Opens the new file in Calc, bypassing the recovery process.
# Requirements:
# - inotify-tools package
# - OpenOffice/LibreOffice Calc installed
DOWNLOAD_FOLDER="$HOME/Downloads"
inotifywait -m -e create --format '%f' "$DOWNLOAD_FOLDER" | while read FILE
do
if [[ $FILE == *.xlsx || $FILE == *.csv || $FILE == *.xls ]]
then
echo "New file detected: $FILE"
# Terminate any running instances of Calc
pkill -f soffice.bin
# Open the new file with Calc, using --norestore to bypass recovery
soffice --calc --norestore --nologo "$DOWNLOAD_FOLDER/$FILE" &
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment