I can’t use keybinds to open recent files, so I thought that we could bypass that using a macro. Has anyone tried this?
I can: alt d z 5 opens 5th Document from file-history
**the keys depends on your locale, start with alt and look which chars in the menu are underscored…
with english UI its alt f u 5
sub showFirstRecent
with GlobalScope.Basiclibraries
If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
end with
key = GetRegistryKeyContent("/org.openoffice.Office.Histories/Histories/org.openoffice.Office.Histories:HistoryInfo['PickList']/OrderList/org.openoffice.Office.Histories:HistoryOrder['0']", false)
MsgBox key.HistoryItemRef
end sub
Thanks for replying! In spanish is Alt+a+d
, but I prefer to use a custom shorter shortcut like Alt+r
.
Hi, thanks for the comment! to me it just shows the name of the most recent file. What I’m looking for is a macro that opens the menu list of the recent files.
Sure. You are given a code that provides the file. You are welcome to continue from here.
Hmm, you expect the menu to open and expand to a wanted position? Then use what @karolus offered, period.
You can try extension History Master
Hi, I did install it, but I can’t make it open it with shortcuts, and it also shows the whole path, which hides the name of the files when they have long paths
I cannot understand what you try to do. @karolus has already given you the solution using a sequence of keys:
1 - alt Select the menu
2 - F Open the File menu
3 - U open the Recent Documents menu
4 - With any number (5 ) you open the document with that number (5th).
Hi again, thanks for your time! What I want is to be able to use my own custom shortcut, just like copy and paste, I could use Alt+e+c
and Alt+e+p
, but it’s much better to just use Ctrl+c
and Ctrl+v
.
Just in case it is helpful for anyone else, I created this Rofi menu as a temporary solution to select the last LO files (it’s in Spanish but quite easy to translate):
#!/bin/bash
# Script para mostrar documentos recientes de LibreOffice con Rofi
# Guarda este archivo como ~/.local/bin/libreoffice-recent-rofi.sh
# Funciona independientemente de si LibreOffice está abierto
# Buscar archivos de configuración de LibreOffice en múltiples ubicaciones posibles
RECENT_FILES=(
"$HOME/.config/libreoffice/4/user/registrymodifications.xcu"
"$HOME/.libreoffice/4/user/registrymodifications.xcu"
"$HOME/snap/libreoffice/common/.config/libreoffice/4/user/registrymodifications.xcu"
"$HOME/.var/app/org.libreoffice.LibreOffice/config/libreoffice/4/user/registrymodifications.xcu"
)
RECENT_FILE=""
for file in "${RECENT_FILES[@]}"; do
if [ -f "$file" ]; then
RECENT_FILE="$file"
break
fi
done
if [ -z "$RECENT_FILE" ]; then
notify-send "LibreOffice Rofi" "No se encontró el archivo de configuración de LibreOffice" -i dialog-error
exit 1
fi
# Función para decodificar URLs
decode_url() {
python3 -c "import sys; import urllib.parse; print(urllib.parse.unquote(sys.argv[1]))" "$1" 2>/dev/null || echo "$1"
}
# Función para detectar el tipo de archivo y abrir con la aplicación correcta de LibreOffice
open_with_correct_app() {
local file="$1"
local extension="${file##*.}"
local app="libreoffice"
case "$extension" in
"odt"|"doc"|"docx"|"rtf"|"txt")
app="libreoffice --writer"
;;
"ods"|"xls"|"xlsx"|"csv")
app="libreoffice --calc"
;;
"odp"|"ppt"|"pptx")
app="libreoffice --impress"
;;
"odg")
app="libreoffice --draw"
;;
"odb")
app="libreoffice --base"
;;
"pdf")
app="libreoffice --draw"
;;
*)
app="libreoffice"
;;
esac
# Abrir el archivo
$app "$file" &>/dev/null &
}
# Extraer las rutas de documentos recientes del archivo XML
recent_docs=$(grep -oE 'file://[^"<>]*' "$RECENT_FILE" | \
grep -iE '\.(odt|ods|odp|odg|odb|odf|doc|docx|xls|xlsx|ppt|pptx|pdf|txt|rtf|csv)($|[^a-zA-Z0-9])' | \
sed 's/file:\/\///' | \
sort -u)
# Si no hay documentos recientes
if [ -z "$recent_docs" ]; then
notify-send "LibreOffice Rofi" "No hay documentos recientes" -i libreoffice-startcenter
exit 0
fi
# Arrays para almacenar los datos
declare -a rofi_display=()
declare -a file_paths=()
# Procesar cada archivo
while IFS= read -r full_path_raw; do
[ -z "$full_path_raw" ] && continue
# Decodificar URL
full_path=$(decode_url "$full_path_raw")
# Verificar si el archivo existe
if [ -f "$full_path" ]; then
filename=$(basename "$full_path")
dirname=$(dirname "$full_path")
# Obtener timestamp y fecha formateada
timestamp=$(stat -c %Y "$full_path" 2>/dev/null || echo "0")
mod_datetime=$(stat -c %y "$full_path" 2>/dev/null | sed 's/\.[0-9]* [+-][0-9]*//' | sed 's/\.[0-9]*//' || echo "")
mod_fecha=$(date -r "$full_path" "+%d/%m/%y" 2>/dev/null || echo "")
mod_hora=$(date -r "$full_path" "+%H:%M" 2>/dev/null || echo "")
# Obtener la fecha de hoy en formato YYYY-MM-DD
today=$(date "+%Y-%m-%d")
# Obtener la fecha del archivo en formato YYYY-MM-DD
file_date=$(date -r "$full_path" "+%Y-%m-%d" 2>/dev/null)
# Decidir qué mostrar según la fecha
if [ "$file_date" = "$today" ]; then
# Es de hoy: mostrar solo la hora
mod_fecha_hora=$(date -r "$full_path" "+%H:%M" 2>/dev/null || echo "")
tabs=1
else
# Es de otro día: mostrar la fecha
mod_fecha_hora=$(date -r "$full_path" "+%d/%m/%y" 2>/dev/null || echo "")
tabs=1
fi
# Seleccionar icono según extensión
case "${filename##*.}" in
"odt"|"doc"|"docx"|"rtf"|"txt") icon="📄" ;;
"ods"|"xls"|"xlsx"|"csv") icon="📊" ;;
"odp"|"ppt"|"pptx") icon="📽️" ;;
"odg") icon="🎨" ;;
"pdf") icon="📕" ;;
*) icon="📄" ;;
esac
## Crear nombre para mostrar
# Crear la cadena de tabulaciones
tabs_str=$(printf '\t%.0s' $(seq 1 $tabs))
# Construir el display_name concatenando las partes
display_name="${mod_fecha_hora}${tabs_str}${icon} ${filename}"
# display_name=$(printf "%-15s %s" "$mod_fecha_hora" "$icon" "$filename")
# display_name="$icon $filename \t ($mod_hora | $mod_fecha)"
# fecha normal y título centrado
# display_name=$(printf "%s%*s" "$mod_fecha" $((70 - ${#mod_fecha})) "$filename")
# original
# display_name="$icon $filename ($(basename "$dirname")) - $mod_datetime"
# Añadir a los arrays con el timestamp para ordenar después
rofi_display+=("$timestamp|$display_name")
file_paths+=("$timestamp|$full_path")
fi
done <<< "$recent_docs"
# Verificar si encontramos archivos válidos
if [ ${#rofi_display[@]} -eq 0 ]; then
notify-send "LibreOffice Rofi" "No se encontraron documentos recientes válidos" -i dialog-warning
exit 0
fi
# Crear array temporal para ordenar
temp_for_sort=()
for i in "${!rofi_display[@]}"; do
timestamp=$(echo "${rofi_display[$i]}" | cut -d'|' -f1)
temp_for_sort+=("$timestamp|$i")
done
# Ordenar por timestamp (más reciente primero) y tomar los primeros 20
mapfile -t sorted_entries < <(printf '%s\n' "${temp_for_sort[@]}" | sort -rn -t'|' -k1 | head -20)
# Extraer los índices ordenados
sorted_indices=()
for entry in "${sorted_entries[@]}"; do
index=$(echo "$entry" | cut -d'|' -f2)
sorted_indices+=("$index")
done
# Construir la lista final para Rofi
final_display=()
final_paths=()
rofi_list=""
for i in "${sorted_indices[@]}"; do
display_line="${rofi_display[$i]#*|}" # Quitar timestamp del display
file_path="${file_paths[$i]#*|}" # Quitar timestamp del path
# Escapar caracteres XML para Rofi
display_escaped=$(echo "$display_line" | sed 's/&/\&/g; s/</\</g; s/>/\>/g')
final_display+=("$display_escaped")
final_paths+=("$file_path")
rofi_list+="$display_escaped\n"
done
# Mostrar Rofi y capturar selección
# selected=$(echo -e "$rofi_list" | rofi -dmenu -i \
# -p "📚 Documentos Recientes LibreOffice:" \
# -theme-str "window {width: 85%; font: \"Sans 9\";} listview {columns: 1; lines: 18;} element {padding: 2px;} element-text {font: \"Sans 9\";}" \
# -kb-accept-entry "Return" \
# -markup-rows)
selected=$(echo -e "$rofi_list" | rofi -dmenu -i \
-p "📚 Documentos Recientes LibreOffice:" \
-theme-str "window {width: 60%;} listview {lines: 15; columns: 1;} element {padding: 1px;} element-text {font: \"Sans 9\";} * {font: \"Sans 9\";}" \
-kb-accept-entry "Return" \
-markup-rows)
# Si se seleccionó algo, encontrar el archivo correspondiente y abrirlo
if [ -n "$selected" ]; then
for i in "${!final_display[@]}"; do
if [ "${final_display[$i]}" = "$selected" ]; then
file_to_open="${final_paths[$i]}"
if [ -f "$file_to_open" ]; then
open_with_correct_app "$file_to_open"
# notify-send "LibreOffice Rofi" "Abriendo: $(basename "$file_to_open")" -i libreoffice-startcenter
else
notify-send "LibreOffice Rofi" "Error: Archivo no encontrado" -i dialog-error
fi
break
fi
done
fi