johan12

Untitled

Apr 4th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. on run {input, parameters}
  2.     --set input to choose file with multiple selections allowed
  3.     set theItems to input
  4.     set zielOrdner to item 1 of input as text
  5.     set AppleScript's text item delimiters to ":"
  6.     set zielOrdner to text items 1 thru -2 of zielOrdner as text
  7.     set zielOrdner to zielOrdner & ":"
  8.     --set zielOrdner to alias zielOrdner
  9.     set pdftkPosixPath to "/opt/pdflabs/pdftk/bin/pdftk"
  10.     display dialog "Passwort der PDF-Datei eingeben:" default answer "" with icon note
  11.     set theAnswer to text returned of the result
  12.     if theAnswer is not "" then set pWord to theAnswer
  13.     --set pWord to ""
  14.     set appendedName to "_temp" -- text to append to the file name
  15.     set shouldTrash to true -- true or false, move the locked file to the trash after unlocking?
  16.     entschluesseln(theItems, appendedName, shouldTrash, zielOrdner, pdftkPosixPath, pWord)
  17. end run
  18. on entschluesseln(theItems, appendedName, shouldTrash, zielOrdner, pdftkPosixPath, pWord)
  19.     set fContainer to zielOrdner as text
  20.     repeat with anItem in theItems
  21.         try
  22.             tell application "System Events"
  23.                 set fName to name of anItem
  24.                 set fExt to name extension of anItem
  25.             end tell
  26.            
  27.             if fExt is "pdf" and fName does not contain appendedName then
  28.                 set baseName to (text 1 thru -5 of fName) & appendedName & ".pdf"
  29.                 set newPath to fContainer & baseName
  30.                 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)
  31.                
  32.                 if shouldTrash then
  33.                     tell application "System Events"
  34.                         delete anItem
  35.                         set name of alias newPath to fName
  36.                     end tell
  37.                 end if
  38.             end if
  39.         on error errText number errNr partial result errList from errSource to errClass
  40.             --display notification "Fehler: " & errText & "Fehlernummer: " & errNr with title "PDF entschlüsseln" subtitle "Fehlermeldung von " & fName sound name ""
  41.             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 ""
  42.             if button returned of myDlg is "OK" then set pWord to text returned of myDlg
  43.             entschluesseln(theItems, appendedName, shouldTrash, zielOrdner, pdftkPosixPath, pWord)
  44.         end try
  45.     end repeat
  46. end entschluesseln
Advertisement
Add Comment
Please, Sign In to add comment