I want to create a thunar custom action that lets me right-click a PDF and then select "split PDF" to split it into individual pages. The command to do this is:
$ pdfseparate mypdf.pdf mypdf-%d.pdf Which will create a new PDF for each page, called mypdf-1.pdf, mypdf-2.pdf, etc. %d is replaced by the pdfseparate command with a page number as per the man page:
SYNOPSIS pdfseparate [options] PDF-file PDF-page-pattern
PDF-page-pattern should contain %d (or any variant respecting printf format), since %d is replaced by the page number.
Thunar custom actions interpolate any %n as the selected file any %d with the directory the file is in. So if I try to replicate the above command, replacing mypdf.pdf with %n, it looks like this:
pdfseparate "%n" "$(basename "%n" .pdf)-%d.pdf" However, then thunar will replace the %d with the file's directory. How can I escape the %d so it will be passed on to pdfseparate verbatim?
pdfseparate does not appear to have an option to use a different variable than %d but it does say it accepts "any variant respecting printf format". I'm not sure what that means... I tried %s and it didn't work.
%%for a literal%, so try something likepdfseparate "%n" "$(basename "%n" .pdf)-%%d.pdf", that might escape the%in%dand pass it as is to pdfseparate. Does that work?"%n"s must be unquoted though or the quotes are interpreted as part of the filename. Thunar must be interpreting the%nliterally because I tested it unquoted on files with spaces in the name and it worked.