AppleScript: Move Files from specific Source- to Target-Folder
Geschrieben am 03. Januar 2010 von OliverKeine Kommentare »
Tags: Development, Solutions

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
- MacUser.de discussion about “Move Files using AppleScript” (DE)
- MacUser.de discussion about “Copy Files using AppleScript” (DE)
- Mac Rumors discussion about “AppleScript get list of Files”
- Apple’s official “AppleScript Language Guide”








