I’m trying to automate some forms using the apple shortcuts app and it’s built in option to run shell script. Basically I have a default pdf that I’ve created for a client that says “dear client”, and I want it to automatically change the name of in the pdf to the client’s name (which I input at the start of the shortcut). I’m using homebrew and trying to use packages like pdfgrep, qpdf, and sed. I also have purchased the mac version of PDFexpert, if I can use some of those commands to more easily edit the files.
I’m doing this on a Macbook Pro M2, and the terminal being used is bash. I guess I could use zshell but I’m not really sure how to use it.
Here is my shell script so far:
Note that the bolded Client Name represents the variable input from my Apple Shortcuts app. Not sure exactly what’s going on under the hood but it seems to work to find files on my computer.
PDF_FILE="/Users/jonathan/Desktop/Personal Trainer Stuff/Client Documents/Signed Client Forms/**Client Name**/**Client Name**_WELCOME_FORM.pdf"
OUTPUT_FILE="/Users/jonathan/Desktop/Personal Trainer Stuff/Client Documents/Signed Client Forms/**Client Name**/**Client Name**_WELCOME_FORM.pdf"
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
qpdf --stream-data=uncompress $1 "$PDF_FILE" --replace-input
sed -i s/("Client")/("**Client Name**")/g "$PDF_FILE"
qpdf --stream-data=compress "$PDF_FILE" $1
I tried this because of what I found on this stackoverflow page: /questions/54749404/cant-edit-pdf-file-with-sed-command
but it keeps corrupting my files or giving me errors. Attached are images of the whole shortcut I’ve written:
[Script](https://i.sstatic.net/3GI6tK8l.jpg)
Jonathan Waldorf is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.