Kontextmenü-Befehl "Datei verschieben nach..." im Finder

F

Fuechsl

Aktives Mitglied
Thread Starter
Dabei seit
30.03.2007
Beiträge
108
Reaktionspunkte
6
Liebe Script-Profis,

Ich würde gerne im Finder mit der rechten Maustaste auf eine Datei klicken können und dann sollte ein Eintrag "Datei verschieben nach..." erscheinen, wenn ich den wählte, öffnete sich ein Ordner-Dialog und ich könnte auswählen, in welchen Ordner ich die Datei verschieben möchte. Lässt sich so etwas scripten? Und wie lege ich es im Kontextmenü des Finders ab?

Danke vielmals für eure schlauen Antworten im Voraus! :)

Liebe Grüsse

Martin
 
Hab ich schon mal gemacht...irgendwann.
Code:
on run {input}
    tell application "System Events"
        set nameInfo to name of item 1 of input
    end tell
    set myPath to choose folder with prompt "Move " & quoted form of nameInfo & " to:"
    tell application "Finder"
        repeat with i in input
            try
                move i to myPath without replacing
            on error errstrg
                if button returned of (display alert "Replacing: " & "'" & name of i & "'?" message errstrg buttons {"Cancel", "OK"} as critical) = "OK" then
                    try
                        move i to myPath with replacing
                    on error errstrg
                        display alert errstrg as critical
                    end try
                end if
            end try
        end repeat
    end tell
end run
 
Zuletzt bearbeitet:
Cool, das war schnell, danke!! Und wie krieg ich das ins Kontextmenü? Kann ich das Script als Dienst speichern und so integrieren?
 
Jup

Bildschirmfoto 2019-11-18 um 22.46.52.png
 
Update:
Code:
on run {input}
--set input to choose file multiple selections allowed yes
tell application "System Events" to set nameInfo to name of item 1 of input
set countInp to count input
if countInp = 1 then
    set dial to "Move " & quoted form of nameInfo & " to:"
else
    set dial to "Move " & quoted form of nameInfo & " + " & countInp - 1 & " files more to:"
end if
set myPath to choose folder with prompt dial
tell application "Finder"
    repeat with i in input
        try
            move i to myPath without replacing
        on error errstrg
            if button returned of (display alert "Replacing: " & quoted form of (name of i as string) & "?" message errstrg buttons {"Cancel", "OK"} as critical) = "OK" then
                try
                    move i to myPath with replacing
                on error errstrg
                    display alert errstrg as critical
                end try
            end if
        end try
    end repeat
end tell
end run
 
Zuletzt bearbeitet:
  • Gefällt mir
Reaktionen: AppleSimmer und KOJOTE
Update:
Ein "timeout" ist hier wichtig da Applescript sonst bei grossen Dateien denkt: "Möhh... da geht nix mehr, beschweren wir uns mal"
Code:
on run {input}
    tell application "System Events" to set nameInfo to name of item 1 of input
    set countInp to count input
    if countInp = 1 then
        set dial to "Move " & quoted form of nameInfo & " to:"
    else
        set dial to "Move " & quoted form of nameInfo & " + " & countInp - 1 & " files more to:"
    end if
    set myPath to choose folder with prompt dial
    with timeout of 86400 seconds
        tell application "Finder"
            repeat with i in input
                try
                    move i to myPath without replacing
                on error errstrg
                    if button returned of (display alert "Replacing: " & quoted form of (name of i as string) & "?" message errstrg buttons {"Cancel", "OK"} as critical) = "OK" then
                        try
                            move i to myPath with replacing
                        on error errstrg
                            display alert errstrg as critical
                        end try
                    end if
                end try
            end repeat
        end tell
    end timeout
end run
PS: Kopiervorgänge die mehrere Stunden dauern, also im gB Bereich sollten sowieso nicht dem Finder übergeben werden, rsync ist dafür besser geeignet.
 
Zuletzt bearbeitet:
  • Gefällt mir
Reaktionen: AppleSimmer und dg2rbf
Genial! Danke!
 
Warum legst du dir nicht einfach eine Schnellaktion mit dem Automator an? Das ist in 10 Sekunden erledigt und im Finder sowohl unter Dienste als auch unter Schnellaktionen abrufbar.

Bildschirmfoto 2019-11-25 um 07.36.23.png

Da die Aktion beim Ablauf angezeigt wird, kannst du vorher das Ziel (voreingestellt ist der Schreibtisch) ganz einfach auswählen.
 
Mein Weihnachtsgeschenk für die Community. Immer gut hier obwohl man sich ab und zu in die Wolle kriegt.
Das Script als Dienst gespeichert gibt einem die Möglichkeit mit rsync zu synchronisieren. Ist die Datenmenge grösser als 10GB wird der Job übersichtshalber an Terminal weitergegeben.
Code:
on run {input}
    set {countInp, nameList, s} to {count input, "", 0}
    tell application "System Events" to set sourcePath to POSIX path of container of item 1 of input
    if countInp = 1 then
        set dial to "rsync " & quoted form of POSIX path of item 1 of input & " to:"
    else
        set dial to "rsync " & quoted form of POSIX path of item 1 of input & " + " & countInp - 1 & " files more to:"
    end if
    activate
    set setDest to choose folder with prompt dial
    tell application "System Events" to repeat with x in input
        if displayed name of x contains "/" then
            with timeout of 3600 seconds
                display alert quoted form of (displayed name of x as string) & " not synced." message quoted form of "/" & " not allowed in file name." buttons {"Cancel", "Skip"} cancel button 1 as critical
            end timeout
        else
            set nameList to nameList & quoted form of (name of x as string) & space
            try
                set s to my getSize(s, x)
            on error erstrg
                display alert erstrg as critical
            end try
        end if
    end repeat
    if nameList = "" then return
    if s < 10000 then
        appShell(sourcePath, nameList, setDest)
    else
        term(sourcePath, nameList, setDest)
    end if
end run

on getSize(s, x)
    s + (word 1 of (do shell script "du -k " & quoted form of (POSIX path of x as string))) / 976.5625
end getSize

on appShell(sourcePath, nameList, setDest)
    try
        do shell script "cd " & quoted form of sourcePath & " ; rsync -rltD --exclude=.DS_Store " & nameList & quoted form of POSIX path of setDest & "&&afplay /System/Library/Sounds/Ping.aiff -v .2"
    on error
        try
            do shell script "cd " & quoted form of sourcePath & " ; rsync -rltD --exclude=.DS_Store " & nameList & quoted form of POSIX path of setDest & "&&afplay /System/Library/Sounds/Ping.aiff -v .2" with administrator privileges
        on error errstrg number errnmb
            if errnmb = -128 then error number -128
            display alert errstrg as critical
        end try
    end try
    try
        display notification nameList with title "rsync:"
    end try
    tell application "Finder"
        open setDest
        activate
    end tell
end appShell

on term(sourcePath, nameList, setDest)
    tell application "Terminal"
        activate
        do script "cd " & quoted form of sourcePath & " ; rsync -vrltD --progress --stats --exclude=.DS_Store " & nameList & quoted form of POSIX path of setDest & "&&afplay /System/Library/Sounds/Ping.aiff -v .2"
    end tell
end term
 
Zuletzt bearbeitet:
  • Gefällt mir
Reaktionen: AppleSimmer und Badoshin
This is a update for #6:
Code:
on run {input}
--set input to choose file multiple selections allowed yes
set countInp to count input
if countInp = 1 then
    set dial to "Move " & quoted form of POSIX path of item 1 of input & " to:"
else
    set dial to "Move " & quoted form of POSIX path of item 1 of input & " + " & countInp - 1 & " files more to:"
end if
activate
set myPath to choose folder with prompt dial
with timeout of 86400 seconds
    repeat with i in input
        tell application "Finder"
            try
                move i to myPath without replacing
            on error errstrg
                display alert "Replacing: " & quoted form of (name of i as string) & "?" message errstrg buttons {"Cancel", "OK"} cancel button 1 as critical
                try
                    move i to myPath with replacing
                on error errstrg
                    display alert errstrg as critical
                end try
            end try
        end tell
    end repeat
end timeout
end run
 
Zuletzt bearbeitet:
  • Gefällt mir
Reaktionen: RabsData
This is a update for #9:
Code:
on run {input}
    --set input to choose file multiple selections allowed yes
    set {countInp, nameList, itemPath, s} to {count input, "", quoted form of POSIX path of item 1 of input, 0}
    set sourcePath to do shell script "dirname " & itemPath
    if countInp = 1 then
        set dial to "rsync " & quoted form of POSIX path of item 1 of input & " to:"
    else
        set dial to "rsync " & quoted form of POSIX path of item 1 of input & " + " & countInp - 1 & " files more to:"
    end if
    activate
    set setDest to choose folder with prompt dial
    tell application "System Events" to repeat with x in input
        if displayed name of x contains "/" then
            with timeout of 3600 seconds
                display alert quoted form of (displayed name of x as string) & " not synced." message quoted form of "/" & " not allowed in file name." buttons {"Cancel", "Skip"} cancel button 1 as critical
            end timeout
        else
            set nameList to nameList & quoted form of (name of x as string) & space
        end if
        try
            set s to s + (my getSize(x))
        on error erstrg
            display alert erstrg as critical
        end try
    end repeat
    if nameList = "" then return
    set sScript to "cd " & quoted form of sourcePath & ";rsync -vrltD --progress --stats --exclude=.DS_Store " & nameList & quoted form of POSIX path of setDest
    if s as number < 10000 then
        appShell(sScript)
    else
        term(sScript)
    end if
end run

on getSize(x)
    (word 1 of (do shell script "du -k " & quoted form of (POSIX path of x as string))) / 976.5625
end getSize

on appShell(sScript)
    try
        do shell script sScript
    on error
        try
            do shell script sScript with administrator privileges
        on error errstrg number errnmb
            if errnmb = -128 then error number -128
            display alert errstrg as critical
        end try
    end try
    do shell script "afplay /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/system/'Volume Mount.aif'"
end appShell

on term(sScript)
    tell application "Terminal"
        activate
        close window 1
        do script sScript & ";afplay /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/system/'Volume Mount.aif'"
    end tell
end term
 
  • Gefällt mir
Reaktionen: tocotronaut
Was heisst Update for #9
Ich will das Script jetzt auch mal abspeichern und Testen, welches ist die beste Version?

Edit... Sind das zwei Scripte? #10 & #11?

Kann ich mit Rsync auch auf SMB Freigaben kopieren?
Macht es Sinn das bei Github zu hosten?
 
Nein, updates sind immer dasselbe Programm nur besser (hoffentlich) Warum willst Du mein Script bei Github hosten?
Ja 10 und 11 sind verschiedene Scripte.
 
Will ich nicht wirklich, aber eine Versionierung ist deutlich besser möglich als hier im Forum...
 
Schau ich mal an. Die Leute die diesen Beitrag aboniert haben werden allerdings benarichtigt. Wenn ich ein Update auf Github lade nicht.
Versuch mal auf SMB hab das nicht in Gebrauch. Gib auch ein Feedback hier ob das geht.
 
  • Gefällt mir
Reaktionen: RabsData
Zurück
Oben Unten