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.

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

 

Share:
  • 2
  • 0

2 thoughts 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

  2. Hello,

    I am getting the following error when I run this script:

    “`Syntax Error
    Expected string but found end of script.“`

    Please let me know what could be causing this. Thank you and have a great day! 🙂

Questions? Suggestions? Let us know with a comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.