AppleScript: Move Files from specific Source- to Target-Folder

AppleScript Logo


I wanted to have an AppleScript application, that takes all the files from a specific Source-Folder and moves* them to a user defined Target-Folder.

After searching my way through different Discussion Boards and the official AppleScript Language Guide, I came up with the following working piece of code:

tell application "Finder"         activate         set source_folder to choose folder with prompt "Please choose the Source-Folder:" default location ((path to home folder) as alias)         set source_files to every file in source_folder         set target_folder to choose folder with prompt "Please choose the Taget-Folder:" default location (":Applications:" as alias)         repeat with i from 1 to number of items in source_files                 set source_file to (item i of source_files)                 move source_file to (target_folder) -- use "copy source_file to folder (target_folder as alias)" to copy the files         end repeat         set question to display dialog "Files have been moved. Move Source-Folder the trash?" buttons {"No, Thanks", "Yes, Please"} default button 2         set answer to button returned of question         if answer is equal to "Ja" then                 tell application "Finder" to delete source_folder         end if         display dialog "Files moved successfully." buttons {"OK"} default button 1 end tell

* If you want to do a copy, instead of moving the files, change the line

move source_file to (target_folder)

to

copy source_file to folder (target_folder as alias)

Sources used

 

One thought on “AppleScript: Move Files from specific Source- to Target-Folder

  1. Hallo Oliver,
    das Script spart Zeit – hast du ev. eine Idee das ganze in Kombi mit Automator und vor der erweiterten Aufgabenstellung:

    - finde alle neue Dateien mit dem Namensteil ttt im Laufwerk XX
    - bewege diese auf das Laufwerk YY mit gleicher Verzeichnisstruktur vom Laufwerk XX

    bin gespannt

    Grüße
    Jörg

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting