Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- on run {input, parameters}
- --set input to choose file with multiple selections allowed
- set theItems to input
- set zielOrdner to item 1 of input as text
- set AppleScript's text item delimiters to ":"
- set zielOrdner to text items 1 thru -2 of zielOrdner as text
- set zielOrdner to zielOrdner & ":"
- --set zielOrdner to alias zielOrdner
- set pdftkPosixPath to "/opt/pdflabs/pdftk/bin/pdftk"
- display dialog "Passwort der PDF-Datei eingeben:" default answer "" with icon note
- set theAnswer to text returned of the result
- if theAnswer is not "" then set pWord to theAnswer
- --set pWord to ""
- set appendedName to "_temp" -- text to append to the file name
- set shouldTrash to true -- true or false, move the locked file to the trash after unlocking?
- entschluesseln(theItems, appendedName, shouldTrash, zielOrdner, pdftkPosixPath, pWord)
- end run
- on entschluesseln(theItems, appendedName, shouldTrash, zielOrdner, pdftkPosixPath, pWord)
- set fContainer to zielOrdner 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 "System Events"
- delete anItem
- set name of alias newPath to fName
- end tell
- end if
- end if
- on error errText number errNr partial result errList from errSource to errClass
- --display notification "Fehler: " & errText & "Fehlernummer: " & errNr with title "PDF entschlüsseln" subtitle "Fehlermeldung von " & fName sound name ""
- set myDlg to display dialog "Fehlermeldung von " & fName & return & "Fehler: " & errText & " Fehlernummer: " & errNr & return & "Passwort der PDF-Datei eingeben:" with title "PDF entschlüsseln" with icon stop default answer ""
- if button returned of myDlg is "OK" then set pWord to text returned of myDlg
- entschluesseln(theItems, appendedName, shouldTrash, zielOrdner, pdftkPosixPath, pWord)
- end try
- end repeat
- end entschluesseln
Advertisement
Add Comment
Please, Sign In to add comment