Created
January 30, 2024 23:32
-
-
Save tiriana/6f9b8fa7861592e3ac0c2271de502f46 to your computer and use it in GitHub Desktop.
Auto-Open Office Script: Watch & Open New Spreadsheet Files in Downloads
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 | |
# 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