This works when you've selected nothing, folders with blank space, a file, a selection of files, etc.
{ [ -d %f ] && exo-open --working-directory %f --launch TerminalEmulator ; } || { exo-open --working-directory %d --launch TerminalEmulator ; }
Available command parameters in thunar Custom Actions:
List of valid command parameter variables
Variable Usage
%f The path of the first selected file.
%F The paths to all selected files.
%u The URI of the first selected file (using the file:-URI scheme).
%U The URIs of all selected files (using the file:-URI scheme).
%d The directory of the first selected file.
%D The directories to all selected files.
%n The name of the first selected file (without the path).
%N The names of all selected files (without the paths).
The above is equivalent to:
if [[ -d %f ]]; then
exo-open --working-directory %f --launch TerminalEmulator
else
exo-open --working-directory %d --launch TerminalEmulator
fi
Or in pseudo-code:
# if the path of the first selected file or directory is a directory
# open a terminal in the directory of the first file selected
# or open a terminal in the directory selected