I am looking for a way to protect pdf-files with a password, but can’t find the properties for it in Acrobat (and Preview seems to be not scriptable?).
I have the script to make the passwords for every page number (and write them to a textfile), than every password will be sent by e-mail to the right person.
But I am stuck now in how to put the passwords into the pdf-file and save them.
I have a script which uses openssl in the terminal to encrypt any file with a password. If you don’t know what openssl is, it’s an open souce toolkit for implementing encryption schemes. Openssl is available for any computer platform. I actually use blowfish encryption in my script.
There’s already a thread about encrypting strings and I took the information from that to make my script for encrypting files. To give you an idea about this encrypting method you can check that thread out here… http://bbs.applescript.net/viewtopic.php?id=19520&p=1*
If you think my script would help you let me know. Basically anyone you send your pdf to would have to know how to decrypt it with this openssl method. If they’re all using Macs then it’s easy because you can send them the applescript to help them decrypt the file, or you can just send them the Terminal command. The terminal command would help linux or unix users too. Windows users would have to first install openssl or some other encrypting/decrypting tool which works with blowfish encryption.
A second way would be… if they’re all using macs then you can put the pdf on an encrypted disk image, and send that to them.
Thanks for you suggestion. I think this solution is to complicated. The files will be sent to too many people; every month different people. That’s not going to work.
I am hoping for an Applescript solution. Is it possible anyway, you think?
I agree about it being too complicated. I only use it for personal stuff.
Here’s another thought. I have a file on my desktop called text.pdf. This script will encrypt it for me using Preview. The number of “tabs” you need might be different, but you can play with it to get it to work. Note: I have “all controls” checked in the “keyboard shortcuts” tab of the “keyboard & mouse” preference pane. This setting affects tabbing around your controls.
set desktopFolder to (path to desktop folder as string)
set fileName to "test.pdf"
set filePath to desktopFolder & fileName
set pass_word to "password"
set myDelay to 2
tell application "Preview"
activate
open filePath
end tell
tell application "System Events" to tell process "Preview"
delay myDelay
keystroke "s" using shift down & command down
delay myDelay
keystroke "encrypted_" & fileName
delay myDelay
repeat 5 times
keystroke tab
delay 0.2
end repeat
delay myDelay
keystroke space
delay myDelay
keystroke return
delay myDelay
keystroke pass_word
delay myDelay
keystroke tab
delay myDelay
keystroke pass_word
delay myDelay
keystroke tab
delay myDelay
keystroke tab
delay myDelay
keystroke return
end tell
Thanks regulus6633. This is more the way I would like to have it. It seems to me that the delay time is really necessary? If I make it shorter to speed up the script, the thing is messed up and doesn’t hit the right checkbox. Uhmm…
I am not really familiar with this keystroke thing, but it looks to me that one can’t do any other thing but waiting till the scripts done. Is that right?
Anyway, this helps me very much (although I am still open to other solutions).
Basically with keystrokes any application is scriptable. It’s not the best solution, but when there’s nothing else at least it works. Gui scripting is another method and sometimes you have to mix the two methods to get what you need. You can search for “gui scripting” for more about that.
As far as the delays, you have to play with them. Some you may not need and some you can probably make shorter. Usually when I script this way I use large delays to get everything working and then tweak them at the end. Delays are a necessary evil because you have to wait for the computer to catch up with your actions.
One thing to remember, when tabbing around with keystokes you use the “space” key to activate a control… whether it be a check box or a button like the “OK” button. And of course the “return” key activates default buttons.
You need to add as unicode text to the end of set desktopFolder to (path to desktop folder
Other wise the set filePath to desktopFolder & fileName
will be → alias Macintosh HD:Users:username:Desktop:, test.pdf
Which forces the Preview to open any image/pdf files it finds on the desktop.
set desktopFolder to (path to desktop folder as unicode text)
set fileName to "test.pdf"
set filePath to desktopFolder & fileName
Mark, that’s funny. Every time I ran that scirpt 2 pdf files were opening up I couldn’t figure out why! I actually trashed the second document to get it to stop opening up. Fortunately that document wasn’t important it trashing it wasn’t an issue.
I’m always good about using “as string”, but in this case I wrote that script fast and didn’t take the time to think it out. At least I learned that Preview can handle a list of objects rather than feeding it one at a time with a repeat loop, and that you can even feed it a folder. Most apps would have probably just given me an error.
Ha, when I ran the script I let out a big WTF, I did it twice before I twigged what was going on. so no worries.
It is handy to know that Preview can do that, but its pretty bonkers.
with the bad path you are asking it in effect to open the desk folder. and it interprets it as open every file in the desktop folder. How the hell does it do that when there is no .sdef library to define how it opens folders?
It kills me that preview doesn’t have a dictionary! I guess Apple wants us to use image events for image manipulation stuff, at least it seems they’re forcing us in that direction.
FYI: I fixed my above code with “as string”. Maybe I should have left it alone so others would learn this lesson! :lol:
Thanks for all the input guys. But I prefer the first solution of Regulus6633 with scripting the GUI. This one is easy for me to implement in the rest of my workflow:
make pdf-files;
check scheme for which page to sent to which client;
then make passwords for all and put them in a text file;
encode all the pdf-files with the appropriate password;
upload encoded pdf-files
sent an e-mail with the password & their pagenumber to every individual client (from the scheme)
All the above things are changing every month, so working from this monthly changing scheme seems the best to me.