Hallo Eder,
ich habe Dir das Droplet per PM zugestellt.
Zum Gebrauch:
– Excel starten;
– das Dokument "neue Namen" / "alte Namen" öffnen;
– den Quellordner mit den PDF-Dateien auf das Icon des Droplets ziehen.
Am Schluss kommt eine Meldung mit der Anzahl der umbenannten Dateien. Es wird auch gemeldet, wieviele Dateien nicht gefunden werden konnten. Oder wieviele neue Namen schon existieren.
Im Excel-Dokument beginnen die Namen in Reihe 3. Die "neuen" Namen sind in Spalte "A", die "alten" Namen befinden sich in Spalte "B".
Der folgende Code im Dateiformat "Programm" gespeichert, ergibt ein Droplet.
Code (* PDFs_umbenennen_01d.app Dieses Script benennt PDF-Dateien anhand eines Excel-Dokumentes um. © 10.03.14 / Hans Häsler, Châtelard 52, CH-1018 Lausanne *) global ctr global folPath global oldNames global newNames global missCtr global probCtr -- einen Dialog zeigen, falls der Anwender einen Doppelklick auf das Droplet macht on run display dialog "Den Quellordner auf das Icon dieses Droplets ziehen." buttons "OK" default button 1 with icon 0 end run -- der 'open handler', welcher auf das Fallenlassen von Objekten reagiert on open allObjects -- Variablen vorbereiten set ctr to 0 set missCtr to 0 set probCtr to 0 -- den Handler aufrufen, welcher prüft, ob Excel läuft testApp() -- den Handler aufrufen, welcher die Namen auflistet getNames() -- das Ergebnis prüfen set nOld to count of oldNames set nNew to count of newNames if nOld is 0 then activate me display dialog "Das Excel-Dokument enthält" & return & "keine \"alten\" Namen." buttons ¬ "OK" default button 1 with icon 0 error number -128 end if if nNew is 0 then activate me display dialog "Das Excel-Dokument enthält" & return & "keine \"neuen\" Namen." buttons ¬ "OK" default button 1 with icon 0 error number -128 end if -- den Inhalt der Namenslisten prüfen if oldNames contains "" then activate me display dialog "Die \"alten\" Namen enthalten ein leeres Feld." buttons ¬ "OK" default button 1 with icon 0 error number -128 else if newNames contains "" then activate me display dialog "Die \"neuen\" Namen enthalten ein leeres Feld." buttons ¬ "OK" default button 1 with icon 0 error number -128 end if -- das erste gedroppte Objekt zum Handler 'processObject' schicken processObject(item 1 of allObjects) -- den Handler aufrufen, welcher den Anwender informiert infUser() end open --/////////////////////////////////////////////////////////////////////////////////////// -- die Handler --/////////////////////////////////////////////////////////////////////////////////////// -- der Handler, welcher prüft, ob Excel läuft on testApp() tell application "System Events" activate set curProc to (name of every process) as string end tell if curProc does not contain "Microsoft Excel" then activate me display dialog "Bitte \"Microsoft Excel\" starten." buttons "OK" default button 1 with icon 2 error number -128 end if end testApp -- alte und neue Namen auflisten on getNames() global tmpList tell application "Microsoft Excel" activate set nDocs to count windows if nDocs is greater than 1 then display dialog "Es darf nur *ein* Excel-Dokument geöffnet sein." buttons ¬ "OK" default button 1 with icon 0 error number -128 else if nDocs is 0 then set filePath to (choose file with prompt "Bitte das Excel-Dokument öffnen.") as Unicode text open filePath end if try tell workbook 1 tell sheet 1 set tmpList to value of used range end tell end tell end try end tell -- das Ergebnis in zwei Listen aufteilen set oldNames to {} set newNames to {} repeat with k from 3 to count of tmpList set end of oldNames to item 2 of item k of my tmpList set end of newNames to item 1 of item k of my tmpList end repeat end getNames -- das Objekt behandeln on processObject(aObject) global oldNames global newNames set folPath to aObject as Unicode text -- wenn der Pfad mit ":" endet, ist das Objekt ein Ordner if folPath ends with ":" then repeat with n from 1 to count oldNames set curPath to folPath & item n of my oldNames set newName to item n of my newNames set newPath to folPath & newName tell application "Finder" if file curPath exists then if not (file newPath exists) then try set name of file curPath to newName set ctr to ctr + 1 end try else set probCtr to probCtr + 1 end if else set missCtr to missCtr + 1 end if end tell end repeat else activate me display dialog "Nur einen *Ordner* droppen." buttons "OK" default button 1 with icon 2 error number -128 end if end processObject -- den Anwender informieren on infUser() activate me if ctr is 0 then display dialog "Fertig." & return & return & "Keine Dateien umbenannt." buttons ¬ "OK" default button 1 with icon 2 else if ctr is 1 then display dialog "Fertig." & return & return & "Nur eine Datei ist umbenannt." buttons ¬ "OK" default button 1 with icon 1 giving up after 5 else display dialog "Fertig." & return & return & ctr & " Dateien sind umbenannt." buttons ¬ "OK" default button 1 with icon 1 giving up after 5 end if if missCtr is 1 then display dialog "Eine Datei nicht gefunden." buttons "OK" default button 1 with icon 2 else if missCtr is greater than 1 then display dialog "" & missCtr & " Dateien nicht gefunden." buttons "OK" default button 1 with icon 2 end if if probCtr is 1 then display dialog "Eine Datei nicht umbenannt." & return & return & ¬ "Der neue Name existiert schon." buttons "OK" default button 1 with icon 2 else if probCtr is greater than 1 then display dialog "" & probCtr & " Dateien nicht umbenannt." & return & return & ¬ "Die neuen Namen existieren schon." buttons "OK" default button 1 with icon 2 end if end infUser Ich habe Excel nur unter "Snow Leopard" installiert. Für "Lion", "Mountain Lion" und "Mavericks" habe ich mir ein Testscript gemacht, in welchem die alten und neuen Namen im Code aufgelistet sind. Mit allen Systemversionen funktionierte das Droplet ohne jede Änderung.
Achtung: Immer ein Backup der Dateien zur Hand haben.
Ich hoffe, dass es wie erwartet funktionieren wird.
Gruss, Hans