Dateiname -> Tag

Hallo,

ich suche eine Möglichkeit, mehreren Files den Namen des jeweiligen Files als Tag hinzuzufügen.

Beispiel:
Vorstandsbericht 2017.doc -> Ein Tag “Vorstandsbericht 2017” wird dem File hinzu gefügt.

Ich kann mir vorstellen, dass dies mit Skripten gelöst werden kann, nur habe ich nichts finden können.

Hat jemand eine Idee?

Viele Grüße!

Mit AppleScript geht dies durchaus, hier ein Beispiel (Einstellungen > Import > Title > Dateiname ohne Erweiterung sollte dazu am besten ausgewählt sein).


tell application id "DNtp"
	set theSelection to the selection
	repeat with theRecord in theSelection
		set theTags to tags of theRecord
		set theTags to theTags & (name of theRecord)
		set tags of theRecord to theTags
	end repeat
end tell

Hi,
das sieht schon mal gut aus. Kann man das Suffix abschneiden?

Also “Vorstandsbericht 2017.doc” -> “Vorstandsbericht 2017”

Das Anpassen der Einstellungen scheint sich nur auf das Feld “Titel” zu beziehen, oder?
Die Dateierweiterung in dem Dateinamen wird leider in den Tag mit übernommen.

Die Einstellung hat nur Einfluss auf Importe, aber nicht auf bereits vorhandene Objekte. Das folgende Skript sollte die Erweiterung entfernen:


tell application id "DNtp"
	set theSelection to the selection
	repeat with theRecord in theSelection
		set theTags to tags of theRecord
		set theName to name of theRecord
		if theName contains "." then -- Strip extension
			set od to AppleScript's text item delimiters
			set AppleScript's text item delimiters to "."
			set theExtension to text item -1 of theName
			-- Check if it's really an extension before stripping
			if (path of theRecord ends with theExtension) then set theName to ((text items 1 thru -2) of theName) as string
			set AppleScript's text item delimiters to od
		end if
		set theTags to theTags & theName
		set tags of theRecord to theTags
	end repeat
end tell

Hi!

Das Skript packt jetzt noch eine weitere Endung hintenan. Nämlich .pdf

-> Vorstandsbericht 2017.doc.pdf

:slight_smile:

Da war leider noch eine Testzeile im Skript enthalten, jetzt müsste es klappen.

Herzlichen Dank!