A robust solution to add an "Open With..." context menu option in muCommander that shows a graphical application selector dialog for any file type.
muCommander's Java environment has limitations when executing external commands:
- Cannot properly resolve
mimetypeandmimeopencommands from the Java PATH - Has issues with file path permissions and accessibility
- Cannot display terminal-based application selectors
- Requires careful handling of command arguments and quoting
This solution creates a bash script that:
- Properly handles file paths passed from muCommander
- Detects the MIME type of the selected file
- Searches for all applications that can handle that MIME type
- Displays a graphical selection dialog using
zenity - Opens the file with the selected application
#!/bin/bash
FILE_PATH="$1"
# Remover comillas simples
if [[ "$FILE_PATH" == \'* ]]; then
FILE_PATH="${FILE_PATH:1}"
fi
if [[ "$FILE_PATH" == *\' ]]; then
FILE_PATH="${FILE_PATH%?}"
fi
if [ ! -f "$FILE_PATH" ]; then
exit 1
fi
export DISPLAY=:0.0
export XAUTHORITY="$HOME/.Xauthority"
# Obtener MIME type
MIME_TYPE="$(/usr/bin/mimetype -b "$FILE_PATH")"
# Mapear MIME de WPS a los MIME estándar usados por LibreOffice
case "$MIME_TYPE" in
application/wps-office.docx)
MIME_TYPE="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
;;
application/wps-office.pptx)
MIME_TYPE="application/vnd.openxmlformats-officedocument.presentationml.presentation"
;;
application/wps-office.xlsx)
MIME_TYPE="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
;;
esac
APPS_FILE="/tmp/mu-apps-$$.txt"
for desktop_file in /usr/share/applications/*.desktop ~/.local/share/applications/*.desktop; do
if [ -f "$desktop_file" ]; then
if grep -q "MimeType=.*$MIME_TYPE" "$desktop_file" 2>/dev/null; then
APP_NAME="$(grep "^Name=" "$desktop_file" | head -1 | cut -d= -f2)"
APP_EXEC="$(grep "^Exec=" "$desktop_file" | head -1 | cut -d= -f2)"
if [ -n "$APP_NAME" ] && [ -n "$APP_EXEC" ]; then
echo "$APP_NAME|$APP_EXEC" >> "$APPS_FILE"
fi
fi
fi
done
if [ -f "$APPS_FILE" ] && [ -s "$APPS_FILE" ]; then
if command -v zenity >/dev/null 2>&1; then
SELECTED="$(cut -d'|' -f1 "$APPS_FILE" | zenity --list \
--title="Abrir con..." \
--column="Aplicación" \
--height=400 \
--width=500)"
if [ -n "$SELECTED" ]; then
APP_CMD="$(grep "^$SELECTED|" "$APPS_FILE" | cut -d'|' -f2 | head -1)"
APP_CMD="$(echo "$APP_CMD" | sed 's/%[fFuU]//g' | sed 's/^"//' | sed 's/"$//')"
eval "$APP_CMD '$FILE_PATH'" &
fi
else
xfce4-terminal -e "/usr/bin/mimeopen -a '$FILE_PATH'"
fi
else
xfce4-terminal -e "/usr/bin/mimeopen -a '$FILE_PATH'"
fi
rm -f "$APPS_FILE"Add the following to your muCommander commands.xml file (typically located in ~/.mucommander/):
<command alias="openWith" value="/path/to/mu-openwith.sh '$f'" display="Open with..." />Replace /path/to/ with the actual path where you saved the script.
-
Save the script:
# Save the script to your home directory nano ~/mu-openwith.sh # Copy and paste the script content
-
Make it executable:
chmod +x ~/mu-openwith.sh -
Edit muCommander commands.xml:
# Navigate to muCommander configuration directory cd ~/.mucommander/ # Edit commands.xml (create if it doesn't exist) nano commands.xml
Add the command configuration inside the
<commands>section:<commands> <!-- Other commands --> <command alias="openWith" value="/home/yourusername/mu-openwith.sh '$f'" display="Open with..." /> </commands>
-
Restart muCommander for the changes to take effect.
The script requires the following packages to be installed:
-
zenity: For graphical dialog (recommended)
sudo apt install zenity # Debian/Ubuntu/MX Linux sudo pacman -S zenity # Arch Linux sudo dnf install zenity # Fedora
-
mimeopen and mimetype: For MIME type detection
sudo apt install shared-mime-info xdg-utils # Debian/Ubuntu/MX Linux -
Terminal emulator (optional, for fallback):
xfce4-terminal(XFCE)xterm(minimal fallback)gnome-terminal(GNOME)konsole(KDE)
-
File Path Handling: The script properly handles file paths passed from muCommander, removing any extra quotes that might be added during argument passing.
-
MIME Type Detection: Uses
mimetypeto determine the file's MIME type (e.g.,text/plain,image/png). -
Application Discovery: Searches through
.desktopfiles in standard locations to find applications registered to handle the detected MIME type. -
Graphical Selection: Presents a clean
zenitydialog listing all available applications. -
Application Execution: Launches the selected application with the file as an argument, running it in the background.
-
"File not found" error in muCommander:
- Ensure the script path in
commands.xmlis correct - Check that the script has execute permissions
- Verify file permissions on the target file
- Ensure the script path in
-
No applications appear in the dialog:
- Check if
mimetypeis installed:which mimetype - Verify the MIME type detection works:
mimetype yourfile.txt - Ensure
.desktopfiles exist for your applications
- Check if
-
Zenity not found:
- Install zenity:
sudo apt install zenity - Or use the terminal fallback by removing the zenity check
- Install zenity:
-
Dialog doesn't appear:
- Check DISPLAY environment:
echo $DISPLAY - Ensure X11 forwarding is enabled if using remote connections
- Check DISPLAY environment:
Test the script manually before using it in muCommander:
# Test with a sample file
~/mu-openwith.sh "/path/to/test.txt"
# Check for errors
echo $? # Should return 0 if successfulIf zenity is not available or preferred, consider these alternatives:
- Terminal-based selection: Use
mimeopendirectly in a terminal - Simple default opener: Use
xdg-opento open with default application - Other dialog tools: Replace
zenitywithkdialog(KDE) oryad(advanced dialogs)
- Tested on: MX Linux 23 (XFCE)
- muCommander version: 1.3.0+
- Shell: Bash 4.4+
- Desktop Environments: XFCE, GNOME, KDE (with zenity)