Skip to content

Add info on how to run this from right click menu #61

@costantinoai

Description

@costantinoai

This is not really an issue, but it would be nice to add information on how to run the extension from the right-click menu on a file, essentially running impress headless.

On Ubuntu, this can be done in nautilus by creating a new script in ~/.local/share/nautilus/scripts/ODP-to-expanded-PDF.sh as follow:

#!/bin/bash

# Define the log file on the desktop
log_file="$HOME/Desktop/expand_animation_log.txt"

# Function to log messages with timestamps
log() {
  echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$log_file"
}

# Start logging
log "Script started."

# Capture initial list of soffice.bin PIDs
initial_soffice_pids=($(pgrep -f soffice.bin))
log "Initial LibreOffice processes (soffice.bin) running: ${initial_soffice_pids[*]}"

# Check if a file path was provided as an argument
if [ -z "$1" ]; then
  log "Error: No file path provided. Usage: $0 <path_to_presentation_file>"
  exit 1
fi

# Get the full path of the input file and define output PDF path
input_file="$(realpath "$1")"
output_pdf="${input_file%.*}.pdf"  # PDF file generated by the macro

# Check if the file has a supported extension
file_extension="${input_file##*.}"
if [[ "$file_extension" != "odp" && "$file_extension" != "ppt" && "$file_extension" != "pptx" ]]; then
  log "Error: Unsupported file extension '$file_extension'. Supported extensions are .odp, .ppt, .pptx."
  exit 1
fi

# Log input and output paths
log "Input file: $input_file"
log "Output PDF (target): $output_pdf"

# Step 1: Run LibreOffice Impress in headless mode with the macro to expand animations
log "Running LibreOffice Impress in headless mode with macro to expand animations."
libreoffice --impress --headless "$input_file" "macro:///ExpandAnimations.ExpandAnimations.Main" &>> "$log_file" &

# Get the LibreOffice process ID
lo_pid=$!

# Allow time for the macro to process, with a 30-second timeout
log "Waiting for output PDF creation (up to 30 seconds)..."
timeout=30  # maximum wait time in seconds
interval=2  # check every 2 seconds
elapsed=0

while [ ! -f "$output_pdf" ] && [ $elapsed -lt $timeout ]; do
  sleep $interval
  elapsed=$((elapsed + interval))
  log "Checked for output PDF; $elapsed seconds elapsed."
done

# Check if the file was created within the timeout
if [ -f "$output_pdf" ]; then
  log "Output PDF created successfully: $output_pdf"
else
  log "Error: Output PDF not created within the timeout period."
fi

# Capture current list of soffice.bin PIDs
current_soffice_pids=($(pgrep -f soffice.bin))
log "Current LibreOffice processes (soffice.bin) running: ${current_soffice_pids[*]}"

# Identify and kill new LibreOffice processes that were not in the initial list
for pid in "${current_soffice_pids[@]}"; do
  if [[ ! " ${initial_soffice_pids[@]} " =~ " $pid " ]]; then
    log "Terminating new LibreOffice process (soffice.bin) with PID: $pid"
    kill -9 "$pid"
  fi
done

# Remove temporary lock file if it exists
lock_file="$(dirname "$input_file")/.~lock.$(basename "$input_file")#"
if [ -e "$lock_file" ]; then
  log "Removing lock file: $lock_file"
  rm "$lock_file"
else
  log "No lock file found to remove."
fi

# Confirm completion and log final message
log "Conversion completed. Check output PDF at $output_pdf."
log "Script finished."

which will results in a new menu item Scripts --> ODP to expanded PDF.

The only modification needed to the source code is to delete the line:

msgbox "Expansion done! See "+newUrlPdf

from the file in

/home/eik-tb/.config/libreoffice/4/user/uno_packages/cache/uno_packages/lu2162478urse.tmp_/ExpandAnimations-0.13.oxt/ExpandAnimations/ExpandAnimations.xba

(make sure to change lu2162478urse with your correct folder name). This turns off the dialog box at the end of the conversion process, which causes LO to get stuck in headless mode (which would be nice to toggle off in a more user-friendly way perhaps :) )

Not sure if this is the right place for this, but I thought I'd share since this was handy for me.

Thanks for the nice tool!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions