I really like that I can add templates to ~/Templates in order to create new files by a template with Nautilus or Caja.

What I like to have improved is the naming of my files.

They are named: Unknown-[Template-Name-Here]. I'd prefer such a format [Template-Name-Here]-[Date] while the date should be in the format YYYY-mm-dd.

Is something like this already possible?

How can I automatize the renaming of my template's file names :)


In this case nautilus scripts are probably the best solution. They are placed in ~/.local/share/nautilus/scripts for nautilus or in ~/.config/caja/scripts for caja and in either case need to be made executable (chmod ug+x $path_to_script).

This script will create a dialog box asking for your choice of template and then create a file based on that template in the current directory, with your desired format:


current_nautilus_dir=$(python -c 'import gio,sys; print(gio.File(sys.argv[1]).get_path())' "$NAUTILUS_SCRIPT_CURRENT_URI")
# python-free:
# current_nautilus_dir=$(echo "$NAUTILUS_SCRIPT_CURRENT_URI" | sed -e 's/%/\\x/g' -e 's_^file://__' | xargs -0 printf "%b" )
template_dir=$(xdg-user-dir TEMPLATES)
template_name=$(find "$template_dir" ! -type d -print0 | sed 's_'$template_dir'/__g' | xargs -0 zenity --list --column=Template)
template_short_name=$(basename "$template_name")
destination_name="${current_nautilus_dir}/${template_short_name}-$(date "+%Y-%m-%d")"

if [ -f "$destination_name" ]
    notify-send "Destination already exists"
    cp "${template_dir}/${template_name}" "$destination_name"

This converts the URI to a path, using the script from here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.