Ordneraktion: Verschiebe Datein aus Ordner A in Ordner C der in Ordner B erstellt wird…?!

16/10/2010
Ja ehm... die Überschrift trifft es ziemlich genau, mehr Worte (z.B. Ordner) würden nur verwirren =)
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

--Ordner-Aktion die alle betroffenen Dateien in einen anderen (neu erstellten Ordner

-- verschiebt, dessen Name vorher abgefragt wird.

-- dieser neue Ordner wird wiederum in einem anderen Ordner erstellt, von dem sich ein Alias

-- in dem Ordner der Ordner-Aktion befindet.

-- Befindet sich bereits eine Datei mit dem gleichen Namen im Zielverzeichnis,

-- wird diese NICHT überschrieben, sondern die neue Datei wird entsprechend umbenannt (durchnummeriert).


-- ehm, um wieviele verschiedene Ordner geht es hier eigentlich?


on adding folder items to this_folder after receiving these_items

try

tell application "Finder"

set folderkind to kind of folder 1 of startup disk

set aliascount to count of every alias file of (this_folder as reference)

--wenn der Alias des Zielordners vorhanden ist kann es weitergehen

if aliascount is 1 then

set destination_folder to (original item of alias file 1 of (this_folder as reference))

set destination_folder_posix to POSIX path of (destination_folder as alias)

--ist der Zielordner auch ein Ordner oder eine Datei? Dann Fehler!

if kind of destination_folder is not folderkind then

error "Hm, der Zielordner ist gar kein Ordner..."

end if

--Ordnernamen abfragen, der im Zielordner angelegt werden soll

set foldername to text returned of (display dialog "Bitte die Ausgabe und das Jahr angeben:" buttons {"Ok"} default button "Ok" default answer "Woche-Jahr")

-- den Ordner anlegen

do shell script "mkdir -p " & quoted form of (destination_folder_posix & foldername)

-- und jetzt jede Datei in den neu angelegten Zielordner bewegen, dabei aber auf doppelte Dateinamen achten und ggf. umbenennen

repeat with this_item in these_items

set item_name to name of this_item

set this_item_posix to POSIX path of (this_item as reference)

set uniq_name to my checkname_with_pdf_suffix(item_name, folder foldername of destination_folder, false)

do shell script "mv " & quoted form of this_item_posix & " " & quoted form of (destination_folder_posix & foldername & "/" & uniq_name)

end repeat

else

error "Zielalias nicht vorhanden oder es gibt mehr als einen Alias..."

end if

end tell

on error msg

display dialog msg

end try

end adding folder items to



to checkname_with_pdf_suffix(n, D, looped)

--check if filename exists in D

-- so if "A File.pdf" exists it names it "A File 1.pdf","A File 2.pdf",...

tell application "Finder"

set thefiles to name of every item of (D as alias)

end tell

if thefiles contains n then

if looped = false then

set n to ((characters 1 through -5 of n) & " 1" & (characters -4 through -1 of n)) as text

my checkname_with_pdf_suffix(n, D, true)

else

set tmp to (last word of ((characters 1 through -5 of n) as text) as integer)

set tmpcount to (count of characters of (tmp as text)) + 5

set tmp to tmp + 1

set n to ((characters 1 through (-1 * tmpcount) of n) & tmp & (characters -4 through -1 of n)) as text

my checkname_with_pdf_suffix(n, D, true)

end if

else

return n

end if

end checkname_with_pdf_suffix

No Comments

CDs/DVDs automatisch nach dem Einlegen kopieren und auswerfen

28/01/2008
Ich sichere gerade meine gesammelten DVDs/CDs auf meinem NAS und das sind so ca. 200.Alle von Hand zu kopieren ist nicht nur nervig, sonder kostet auch viel Zeit, da ich nicht immer gleich mitbekommen, wenn ein Kopiervorgang fertig ist.Deshalb habe ich eine Ordner-Aktion geschrieben, die ich an den unsichtbaren "Volumes" Ordner angehängt habe. Sobald nun ein neues Medium eingelegt wird, wird dieses nach einem kurzen Dialog mit Timeout auf das NAS kopiert und anschließend ausgeworfen.Hier zunächst einmal der Code:  
Code zum markieren einmal anklicken

--Folder action to copy contents of inserted media to some other place...

on adding folder items to this_folder after receiving these_items

try

tell application "Finder"

set b to POSIX path of ((original item of alias file "COPYALIAS" of startup disk) as alias)

end tell

repeat with this_ in these_items

tell application "Finder"

display dialog ("copy " & (name of this_) & "?") as text giving up after 3

set itemname to name of this_

set copypath to (original item of alias file "COPYALIAS" of startup disk)

set a to POSIX path of this_

--set a to (characters 1 through -2 of a) as text

end tell

set bb to checkname_now_suffix(itemname, copypath, false)

do shell script "cp -R " & quoted form of a & " " & quoted form of b & quoted form of bb

tell application "Finder"

eject this_

end tell

end repeat

on error msg

tell application "Finder"

activate

display dialog msg

end tell

end try

end adding folder items to


on checkname_now_suffix(n, D, looped)

tell application "Finder"

set thefiles to name of every item of D

end tell

if thefiles contains n then

if looped = false then

set n to n & " 1"

else

set cc to count of every character of last word of n

set cn to ((last word of n) as integer) + 1

set n to ((characters 1 through (-1 * (cc + 1)) of n) as text) & cn

checkname_now_suffix(n, D, counter, true)

end if

else

return n

end if

end checkname_now_suffix


Man zieht einen Alias von dem Zielverzeichnis direkt auf das Start-Volumen und nennt ihn "COPYALIAS" so weiss das Skript, wohin kopiert werden soll.
No Comments