property type_list : {"PDF"}
property extension_list : {"PDF"}
property post_alert : "Anzeigen"
property pfad_sejda : {"Noch nicht festgelegt"}
property pfad_ziel : {"Noch nicht festgelegt"}
on run
set loop_dialog to true
repeat while loop_dialog is true
display dialog "Bitte legen Sie eines oder mehrere PDF-Dokumente, die halbiert werden sollen, auf dem Symbol dieses Skripts ab." & linefeed & linefeed & "Benachrichtungen: " & (post_alert as text) & linefeed & "Pfad zu Sejda: " & (pfad_sejda as text) & linefeed & "Pfad für bearbeitete PDF-Dateien: " & (pfad_ziel as text) buttons {"Pfad-Einstellungen", "Benachrichtigungen", "Beenden"} default button 3 with title "PDF-Halbieren-Skript" with icon stop
if the button returned of the result is "Pfad-Einstellungen" then
set loop_einstellungen to true
repeat while loop_einstellungen is true
display dialog "Wählen Sie die zu ändernden Einstellung aus." & linefeed & linefeed & "Pfad zu Sejda: " & (pfad_sejda as text) & linefeed & "Pfad für bearbeitete PDF-Dateien: " & (pfad_ziel as text) buttons {"Pfad zu Sejda", "Pfad für bearbeitete PDF-Dateien", "Zurück"} default button 3 with title "Einstellungen"
if the button returned of the result is "Pfad für bearbeitete PDF-Dateien" then
set loop to true
repeat while loop is true
display dialog "Wo sollen die geteilten PDF-Dokumente gespeichert werden? Geben Sie den kompletten Pfad an oder wählen Sie ein Verzeichnis aus." & linefeed & linefeed & "Im Pfadnamen darf kein Leerzeichen enthalten sein." & linefeed & linefeed & "Aktueller Pfad:" & linefeed & linefeed & pfad_ziel default answer pfad_ziel buttons {"Verzeichnis wählen", "Speichern"} default button 2
if the button returned of the result is "Verzeichnis wählen" then
set pfad_ziel to POSIX path of (choose folder with prompt "Speicherordner wählen")
else
set pfad_ziel to the text returned of the result
set loop to false
end if
end repeat
return pfad_ziel
else if the button returned of the result is "Pfad zu Sejda" then
set loop2 to true
repeat while loop2 is true
display dialog "Wo ist das Programm Sejda gespeichert? Geben Sie den kompletten Pfad an oder wählen Sie ein Verzeichnis aus." & linefeed & linefeed & "Im Pfadnamen darf kein Leerzeichen enthalten sein." & linefeed & linefeed & "Aktueller Pfad:" & linefeed & linefeed & pfad_sejda default answer pfad_sejda buttons {"Verzeichnis wählen", "Speichern"} default button 2
if the button returned of the result is "Verzeichnis wählen" then
set pfad_sejda to POSIX path of (choose folder with prompt "Ordner zu Sejda wählen")
return pfad_sejda
else
set pfad_sejda to the text returned of the result
set loop2 to false
end if
end repeat
return pfad_sejda
else
set loop_einstellungen to false
end if
end repeat
else if the button returned of the result is "Benachrichtigungen" then
display dialog "Soll eine Meldung angezeigt werden, wenn das zu verarbeitende Dokument kein PDF-Dokument ist?" & return & return & "Benachrichtungen: " & (post_alert as text) buttons {"Nicht anzeigen", "Anzeigen"} default button 2
if the button returned of the result is "Anzeigen" then
set post_alert to "Anzeigen"
else
set post_alert to "Nicht anzeigen"
end if
else if the button returned of the result is "Beenden" then
set loop_dialog to false
else
set loop_dialog to true
return "done"
end if
end repeat
return "beenden"
end run
on open these_items
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
set the item_info to info for this_item
set this_name to the name of the item_info
set this_file to POSIX path of this_item
try
set this_extension to the name extension of item_info
on error
set this_extension to "falsch"
end try
try
set this_filetype to the file type of item_info
on error
set this_filetype to "falsch"
end try
if ((this_filetype is in the type_list) or (this_extension is in the extension_list)) then
process_item(this_file)
else if post_alert is "Anzeigen" then
display dialog "Die Datei" & linefeed & linefeed & this_name & linefeed & linefeed & "kann nicht verarbeitet werden, da es sich um kein PDF-Dokument handelt." & linefeed & linefeed & "Benachrichtungen: " & (post_alert as text) buttons {"Benachrichtigungseinstellung", "Überspringen"} default button 2 with title "PDF-Halbieren-Skript" with icon caution
if the button returned of the result is "Benachrichtigungseinstellung" then
display dialog "Soll eine Meldung angezeigt werden, wenn das zu verarbeitende Dokument kein PDF-Dokument ist?" & return & return & "Benachrichtungen: " & (post_alert as text) buttons {"Nicht anzeigen", "Anzeigen"} default button 2
if the button returned of the result is "Anzeigen" then
set post_alert to "Anzeigen"
else
set post_alert to "Nicht anzeigen"
end if
else
return "done"
end if
end if
end repeat
end open
on process_item(this_item)
do shell script (pfad_sejda & "bin/sejda-console splitdownthemiddle -f " & this_item & " -o " & pfad_ziel)
end process_item