Score:1

Show input filename within output filename — after ghostscript command

br flag

I use this script (from here) in order to reduce the size of a pdf file:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook \ -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

I have added this within a Dolphin action (service menu) with the line:

Exec=bash -c 'pdf=$(gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook    -sOutputFile=ebook.pdf "%u"); kdialog --title "Shrink" --msgbox "Done! $pdf";';

I would like the output file name to be automatically based on that of the input file, something like: input_xxx.

hr flag
I'd try something like `f="%u"; pdf=$(gs ... -sOutputFile="${f%.pdf}_xxx}" "$f"); ...`
br flag
@steeldriver - that's the answer. Could you post it as such? (Only, instead of `"${f%.pdf}_xxx}"`, it should be `"${f%.pdf}_xxx"`.)
hr flag
Ooops sorry about that - done
br flag
I meant `"${f%.pdf}_xxx.pdf"` for my specific script.
Score:1
hr flag

If you assign the %u value to a shell variable, it should be possible to use standard variable expansion syntax ${var%.ext}_xxx to remove the .pdf extension and add a suffix of your choice:

bash -c 'f="%u"; pdf=$(gs -dQUIET -dBATCH [pdf options] -sOutputFile="${f%.pdf}_xxx" "$f"); ...'
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.