您听说过“文件夹操作”吗?这是一种将 applescript 附加到文件夹的方法,以便每当将新文件添加到文件夹时,applescript 就会运行。一个快速的谷歌搜索出现了这个,它将为您提供如何设置它的指导。如果您仍有疑问,可以进行更多谷歌搜索。
这是一个可用于文件夹操作的 applescript。我没有测试它,但它应该可以工作(它是基本代码)。这只会在 pdf 文件上完成它的工作。您添加到文件夹中的其他文件将被单独保留。注意:您必须输入脚本前 4 个变量的值。
祝你好运。
on adding folder items to theFolder after receiving theItems
-- enter your values here
set pdftkPosixPath to "/usr/bin/pdftk"
set pWord to "foopass"
set appendedName to "_unlocked" -- text to append to the file name
set shouldTrash to true -- true or false, move the locked file to the trash after unlocking?
set fContainer to theFolder as text
repeat with anItem in theItems
try
tell application "System Events"
set fName to name of anItem
set fExt to name extension of anItem
end tell
if fExt is "pdf" and fName does not contain appendedName then
set baseName to (text 1 thru -5 of fName) & appendedName & ".pdf"
set newPath to fContainer & baseName
do shell script (quoted form of pdftkPosixPath & space & quoted form of POSIX path of anItem & " input_pw " & quoted form of pWord & " output " & quoted form of POSIX path of newPath)
if shouldTrash then
tell application "Finder" to move anItem to trash
end if
end if
end try
end repeat
end adding folder items to
编辑:这是您如何要求输入密码的方法。请注意,如果您想查看文本,请删除“隐藏答案”。
display dialog "Enter a password:" default answer "" with icon note with hidden answer
set theAnswer to text returned of the result
if theAnswer is not "" then set pWord to theAnswer