Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5

Automator Dienst erstellen
#1

Hallo ich möchte gerne einen Automator Dienst erstellen der folgendes bewerkstelligt:
Ich habe diverse Homevideos die sich wie folgt nennen VID_XXXXXXX_DATUM
davon halt sehr viele (so um die 2000) diese Dateien möchte ich gerne Umbenennen so das das vorausgehende VID_ entfernt wird und dann in Ordner verschoben werden. Diese Ordner wiederum sollen automatisch in den Namen der Datei Umbenannt werden.

Wie bewerkstellige ich das mit dem Automator???
Oder vielleicht mit Applescript?

Welche vorgehensweise wäre sinnvoll?

Ein Automator Dienst habe ich mir schon erstellt um Dateien umzubenennen.
Zitieren
#2

Hi

Ich habe mal etwas in Applescript gebastelt. Es handelt sich hier um ein Droplet. Du kannst diese App an beliebiger Stelle ablegen. Ziehe dann einfach ein oder mehrere Videos auf dieses Droplet. Das Droplet schneidet den Teil "VID_" ab, erzeugt einen Ordner mit dem Dateinamen und verschiebt das Video in diesen Ordner.

Das Droplet ist zwar kein Dienst. Aber man könnte es entsprechend umbauen. Der Vorteil beim Droplet ist allerdings, dass Du einfach mehrere Datein gleichzeitig bearbeiten kannst, indem Du sie auf das Droplet ziehst.

Hier der Code:

Code:
on open theDropped
    
    repeat with MyFile in theDropped
        set countpos to 0 as number
        tell application "Finder"
            set MyFile to MyFile as alias
            set NameOfFile to (name of (info for MyFile))
            set ofsp to (length of NameOfFile)
            set Pref to characters 1 thru 4 of NameOfFile as text
            set NameOfFile to characters 5 thru ofsp of NameOfFile as text
            set ofsp to length of NameOfFile
            repeat ofsp times
                set countpos to countpos + 1 as number
                set checkletter to characters countpos thru countpos of NameOfFile as text
                if checkletter = "." then
                    set countpos to countpos - 1
                    exit repeat
                end if
            end repeat
            set NameOfFolder to characters 1 thru countpos of NameOfFile as text
            set myPath to container of MyFile as text
            set DestinationFile to POSIX path of myPath as text
            set NameOfFile to DestinationFile & "/" & NameOfFolder & "/" & NameOfFile as text
            set NameOfFolder to DestinationFile & NameOfFolder as text
        end tell
        
        if Pref = "VID_" then
            set MyFile to MyFile as text
            set MyFile to POSIX path of MyFile as text
            set MyFile to quoted form of MyFile as text
            set NameOfFile to quoted form of NameOfFile
            try
                do shell script "mkdir " & NameOfFolder
            end try
            try
                do shell script "mv " & MyFile & " " & NameOfFile
            end try
        end if
    end repeat
    
end open

Und hier das fertige Droplet:

.zip SortAndRename.app.zip Größe: 56,76 KB  Downloads: 64


Gruss

lifeflow

P.S.: Vor dem ersten Einsatz bitte unbedingt eine Sicherung durchführen. Nur für den Fall, dass etwas schief läuft!
Zitieren
#3

Hier noch eine Korrektur...

Das Script hatte Probleme mit Leerschlägen in Ordner- und Dateinamen. Ist in dieser Version korrigiert.

Code:
on open theDropped
    
    repeat with MyFile in theDropped
        set countpos to 0 as number
        tell application "Finder"
            set MyFile to MyFile as alias
            set NameOfFile to (name of (info for MyFile))
            set ofsp to (length of NameOfFile)
            set Pref to characters 1 thru 4 of NameOfFile as text
            set NameOfFile to characters 5 thru ofsp of NameOfFile as text
            set ofsp to length of NameOfFile
            repeat ofsp times
                set countpos to countpos + 1 as number
                set checkletter to characters countpos thru countpos of NameOfFile as text
                if checkletter = "." then
                    set countpos to countpos - 1
                    exit repeat
                end if
            end repeat
            set NameOfFolder to characters 1 thru countpos of NameOfFile as text
            set myPath to container of MyFile as text
            set DestinationFile to POSIX path of myPath as text
            set NameOfFile to DestinationFile & "/" & NameOfFolder & "/" & NameOfFile as text
            set NameOfFolder to DestinationFile & NameOfFolder as text
        end tell
        
        if Pref = "VID_" then
            set MyFile to MyFile as text
            set MyFile to POSIX path of MyFile as text
            set MyFile to quoted form of MyFile as text
            set NameOfFile to quoted form of NameOfFile as text
            set NameOfFolder to quoted form of NameOfFolder as text
            try
                do shell script "mkdir " & NameOfFolder
            end try
            try
                do shell script "mv " & MyFile & " " & NameOfFile
            end try
        end if
    end repeat
    
end open

.zip SortAndRename.app.zip Größe: 56,87 KB  Downloads: 64
Zitieren
#4

Und zum Abschluss das Ganze noch als Dienst, falls Dir das lieber ist. Der wandelt halt immer nur die gerade markierte Datei um. Langsam bekomme ich Übung mit dem Automator Zwinkern

   

Hier der Scriptcode:

Code:
on run
    set countpos to 0 as number
    tell application "Finder"
        set MyFile to selection as alias
        set NameOfFile to (name of (info for MyFile))
        set ofsp to (length of NameOfFile)
        set Pref to characters 1 thru 4 of NameOfFile as text
        set NameOfFile to characters 5 thru ofsp of NameOfFile as text
        set ofsp to length of NameOfFile
        repeat ofsp times
            set countpos to countpos + 1 as number
            set checkletter to characters countpos thru countpos of NameOfFile as text
            if checkletter = "." then
                set countpos to countpos - 1
                exit repeat
            end if
        end repeat
        set NameOfFolder to characters 1 thru countpos of NameOfFile as text
        set myPath to container of MyFile as text
        set DestinationFile to POSIX path of myPath as text
        set NameOfFile to DestinationFile & "/" & NameOfFolder & "/" & NameOfFile as text
        set NameOfFolder to DestinationFile & NameOfFolder as text
    end tell
    
    if Pref = "VID_" then
        set MyFile to MyFile as text
        set MyFile to POSIX path of MyFile as text
        set MyFile to quoted form of MyFile as text
        set NameOfFile to quoted form of NameOfFile as text
        set NameOfFolder to quoted form of NameOfFolder as text
        try
            do shell script "mkdir " & NameOfFolder
        end try
        try
            do shell script "mv " & MyFile & " " & NameOfFile
        end try
    end if
end run
Zitieren
#5

Noch eine letzte Anpassung...

Diese Scriptversion ist auch für den Dienst geeignet. Du kannst hier gleich mehrere Dateien im Finder markieren und bearbeiten lassen. Dateien, deren Name nicht mit "VID_" beginnt, werden automatisch ignoriert.

Code:
on run
    tell application "Finder" to set TheMarked to selection
    repeat with MyFile in TheMarked
        set countpos to 0 as number
        tell application "Finder"
            set MyFile to MyFile as alias
            set NameOfFile to (name of (info for MyFile))
            set ofsp to (length of NameOfFile)
            set Pref to characters 1 thru 4 of NameOfFile as text
            set NameOfFile to characters 5 thru ofsp of NameOfFile as text
            set ofsp to length of NameOfFile
            repeat ofsp times
                set countpos to countpos + 1 as number
                set checkletter to characters countpos thru countpos of NameOfFile as text
                if checkletter = "." then
                    set countpos to countpos - 1
                    exit repeat
                end if
            end repeat
            set NameOfFolder to characters 1 thru countpos of NameOfFile as text
            set myPath to container of MyFile as text
            set DestinationFile to POSIX path of myPath as text
            set NameOfFile to DestinationFile & "/" & NameOfFolder & "/" & NameOfFile as text
            set NameOfFolder to DestinationFile & NameOfFolder as text
        end tell
        
        if Pref = "VID_" then
            set MyFile to MyFile as text
            set MyFile to POSIX path of MyFile as text
            set MyFile to quoted form of MyFile as text
            set NameOfFile to quoted form of NameOfFile as text
            set NameOfFolder to quoted form of NameOfFolder as text
            try
                do shell script "mkdir " & NameOfFolder
            end try
            try
                do shell script "mv " & MyFile & " " & NameOfFile
            end try
        end if
    end repeat
end run
Zitieren


Möglicherweise verwandte Themen…
Thema / Verfasser Antworten Ansichten Letzter Beitrag
Letzter Beitrag von snowman78
06.06.2013, 15:37



Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste