「フォルダアクション」について聞いたことがありますか?これは、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