Script zur Dateisuche

Hallo in die Runde,

Benutze bisher folgenden Workflow:

ScanSnap scannt Dokumente als PDF und

a) leitet sie an die DevonThink 3.app weiter, dort OCR mit AbbyFineReader, stehen dann im DT-Eingangsordner als PDF+Text mit dem Namen „jjjj_MM_dd_TT_mm_ss“

b) zusätzlich wird beim Scan die unbearbeitete PDF-Datei mit demselben Namen in einem separaten Zielordner abgelegt (sozusagen als zusätzliche Kopie und externe Sicherung)

Über die Jahre hinweg haben sich nun im Eingangsordner Tausende Dateien gesammelt, ich will da jetzt etwas aufräumen, sortieren und umbenennen.

Vorher möchte ich aber sicher sein, dass es die externe Sicherungsdatei gleichen Names noch gibt und sie mit dem DT-Eintrag verknüpfen, bevor ich den umbenenne.

Ich stelle mir da in etwa so ein Script vor:

„Für jedes Item im DT-Eingangsordner → schau im Finder im Ordner „XYZ“ nach, ob es dort eine Datei gleichen Namens gibt → Falls ja, versehe das Item mit einem grünen Label und setze den bisherigen Namen zusätzlich als Alias“

Scripte neu zu entwerfen ist ziemlich schwierig, bestehende Scripte abändern und anpassen, trau ich mir schon eher zu.

Hat jemand ein Script, dass sowas macht. Oder sowas ähnliches, könnte ich dann anpassen.

Vielen Dank für Eure Hilfe

Erik

Dieses einfache Skript vergleicht z.B. den Inhalt eines Finder-Ordners mit den in DEVONthink ausgewählten Objekten:


property pPath : "/path/to/your/folder/" -- Customize the path first

tell application "Finder"
	set theseFilenames to name of every item of folder ((POSIX file pPath) as alias)
end tell

tell application id "DNtp"
	repeat with theRecord in selected records
		set thePath to path of theRecord
		if thePath is not "" then
			tell application "Finder" to set theFilename to (name of ((POSIX file thePath) as alias) as string)
			
			ignoring case
				if theseFilenames contains theFilename then
					-- Insert desired actions here
				end if
			end ignoring
		end if
	end repeat
end tell

Super, vielen Dank schonmal.

Dann werd ich mal ans Basteln gehen

Erik

Hallo nochmal,

Das Script hat soweit gut funktioniert und tut, was ich will.
Nur das Kopieren im Finder klappt nicht. Bekomme entweder Fehlermeldungen, dass er die
Datei nicht lesen kann oder dass die Variable dest nicht in einen alias umgewandelt werden kann.

Wo mache ich da einen Fehler ?

Vielen Dank schonmal und Gruß
Erik


property pPath : "users/erik/documents/Belegeingang_Neu/" -- Customize the path first
property zpath : "users/erik/documents/Belegeingang_Ziel/"

.........
.........

ignoring case

if theseFilenames contains theFilename then
-- Insert desired actions here
    -- Der Eintrag in DT wird grün markiert und der bisherige Name als Alias eingertagen...
    set label of theRecord to 2
    set aliases of theRecord to name of theRecord

    --- dann das Kopieren im Finder---
    tell application "Finder"
        set sfile to (pPath & theFilename) as string
        set source to (POSIX file sfile) as alias
        set zfile to (zpath & theFilename) as string
        set dest to (POSIX file zfile) as alias

        move file source to folder dest
    end tell
end if

end ignoring

Sollte das nicht /Users…heißen, also mit einem Slash vorne? Und zwar in beiden Fällen.

So, Problem gelöst :grinning:

Nach langem Gefrickel und Probieren (mit Alias und String und POSIX und Path usw.) tut dieses Script jetzt das, was ich wollte:
Mein Quellordner (Sammelorder für eingegangene Scans) wird durchsucht, ob für jede Datei dort auch ein Eintrag in der DT-Datenbank vorhanden ist, dieser Eintrag dann mit grünem Label markiert und die Datei in ein neues Zielverzeichnis bewegt.
Übrig bleiben dann im Quellordner alle Dateien, die ich noch in DT importieren muss und übrig bleiben in DT alle rot markierten Einträge, für es noch keine externe Datensicherungsdatei gibt.

Ausserdem wird für jeden Eintrag in DT der bisherige Dateiname als Alias hinterlegt, sodaß ich den Eintrag jetzt sinnvoll umbenennen kann.

Vielen Dank für die Hilfe, schönen Sonntag.

Gruß Erik

--------------------------------------------------------------------------------------------------

property pPath : "users/..../documents/Quellordner/" -- Customize the path first
property zPath : "users/..../documents/Zielordner/"

tell application "Finder"
set theseFilenames to name of every item of folder ((POSIX file pPath) as alias)
end tell

tell application id "DNtp"
repeat with theRecord in selected records
	set thePath to path of theRecord
	if thePath is not "" then
		tell application "Finder" to set theFilename to (name of ((POSIX file thePath) as alias) as string)
	
		ignoring case
			if theseFilenames contains theFilename then
				-- Insert desired actions here
				set label of theRecord to 2 -- grün
				set aliases of theRecord to filename of theRecord
				
				tell application "Finder"
					set source to POSIX file (pPath & theFilename) as alias
					set dest to ((POSIX file zPath) as alias)
					
					move file source to folder dest
				end tell
			else
				set label of theRecord to 1 -- rot
			end if
		end ignoring
	end if
end repeat
end tell
1 Like