You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automator: Watermark PDF Documents not working

Hi,


The "Watermark PDF Documents" action of Automator is not working.


No matter which files you choose, and I tested a lot of combinations, the action ends up with the following error:


"Watermark PDF Watermark failed - 1 error"

"Command line tool returned error 1. (1)"


User uploaded file


I have a clean Install of Yosemite. I tested with 2 more Mac Book Pro's with Yosemite and the same happen.


To replicate you just have to create a new Automator, with 2 actions:

- Get Specified Finder Items, and choose a PDF file

- Watermark PDF Documents, and choose a PNG or JPG file


Run and see the error.


Thank you.

MacBook Pro, OS X Mavericks (10.9)

Posted on Oct 23, 2014 3:24 AM

Reply
53 replies

Nov 16, 2014 8:46 AM in response to Re.flex

Hiroto solved the problem in the discussion he linked.


To summarize:

1. Copy "/System/Library/Automator/Watermark PDF Documents.action/Contents/Resources/tool.py" to a folder of your choice (I used /Users/Tony/Library/Scripts)

2. Change line 29

from:

provider = CGDataProviderCreateWithFilename(imagePath)

to:

url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, imagePath, len(imagePath), False)

3. After line 75 add:

scale = 1.0

4. Then make it executable:

chmod u+x ~/Library/Scripts/tool.py


In Automator, do not use the Watermark Workflow, use this Run Shell Script Workflow (and pass input [as arguments]):

~/Library/Scripts/tool.py \
--under \
--xOffset 15 \
--yOffset 55 \
--angle 0 \
--scale 0.75 \
--opacity 0.5 \
--input "$1" \
--output "${1%.*} (COPY).${1##*.}" \
~/Pictures/Other\ Images/Watermark\(COPY\).png


Adjust settings as needed, and for the last line, use the path to your watermark

Nov 17, 2014 6:29 AM in response to Tony T1

Thank you for this !

I don't know anything in programming, but I feel I am about to solve my big watermarks problem!! Could you just tell me how I can open the action file to change the code as you describe?

And secondly, what do you mean with

4. Then make it executable:

chmod u+x ~/Library/Scripts/tool.py

where/how does this has to happen?


Thank you very much !!!

Nov 17, 2014 9:15 AM in response to jbdumont

You can copy it to the Desktop.

Open Terminal (Applications->Utilities)

Enter:

cp "/System/Library/Automator/Watermark PDF Documents.action/Contents/Resources/tool.py" ~/Desktop


Now open tool.py on the Desktop with TextEdit

Make the 2 changes described above and save

Then in Terminal enter:

chmod u+x ~/Desktop/tool.py


You can then copy tool.py to any Folder you wish and use the Run Shell Script action in Automator described above.

Nov 18, 2014 6:22 AM in response to jbdumont

The last line is the path and filename to where your watermark is located.

In my example, I'm using a watermark named "Watermark(COPY).png" located in "Pictures/Other Images" in my Home Directory (the shortcut of which is ~)

Spaces and parenthesis need to be escaped with a backslash (\) or use of quotes.

…so the path and filename in my example is: ~/Pictures/Other\ Images/Watermark\(COPY\).png

Nov 18, 2014 6:43 AM in response to Tony T1

Thank you again for your help!

Unfortunately, I get an error message: " Failed to run a shell script - Traceback (most recent call last)".

Not sure if you can help me with this :-) Or is there something obvious that I don't see?
Thanks a lot, but don't waste time on my case, I am slowly considering to do all my watermarks manually as in the good old days :-(((


User uploaded file

Nov 18, 2014 9:18 AM in response to jbdumont

Hello


You need to replace this line:


provider = CGDataProviderCreateWithFilename(imagePath)


with the following two lines:


url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, imagePath, len(imagePath), False) provider = CGDataProviderCreateWithURL(url)



Or the following one line if you prefer:


provider = CGDataProviderCreateWithURL(CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, imagePath, len(imagePath), False))


Note that python is a peculiar language where indentation has speciial meaning to denote level of code block. You need to be very careful to preserve the indentation of the snippet above as 1 tab in the target code. (Replace the 4-spaces indentation of the snippet posted above with 1 tab in the target code. Otherwise python code won't work.)



Indeed it would be much easier to copy the entire code of the modified tool.py posted in the linked thread into a new file. 😉


https://discussions.apple.com/thread/6620337



Good luck,

H



PS. By the way, you may also open action's package via contextual menu item "Show Package Contents", which you can show with right clicking (control left clicking) on the Watermark PDF Documents.action.

Nov 18, 2014 2:53 PM in response to Hiroto

Hi Hiroto and Tony,


Thank you very much for your help... even if I didn't sort it all yet! But I am willing to go through it :-)

I will recap step by step w I do so that you can see if I make a stupid mistake somewhere


1/ I open TextEdit, I select text mode, I copy all Hiroto's code and I get this file: https://www.dropbox.com/s/tn9fbcnvfdve751/tool.py


2/ I save this file as tool.py, let's say on my desktop.


3/ I open terminal, I do this:

User uploaded file


4/ I make a new process in Automator:

User uploaded file


Do you see what I do wrong ?? I think I really follow what you say, but it doesn't work... :'-(

Thank you !!!

Automator: Watermark PDF Documents not working

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.