Choose folder command to create "Hot" folder

Hello,

I’m pretty new to applescript. At this moment i’m using a folder action to create a “hot” folder, which duplicates the files placed in this folder live to another backup folder.

This is the script i’m using as folder action and it works fine:


on adding folder items to this_folder after receiving these_items
	tell application "Finder" to duplicate these_items to folder ("Macintosh HD:Users:photograper:Desktop:Target:")
end adding folder items to

But I wan’t to combine this script with a “Choose folder” command. So I can save the script as an application and manually point a specific source and target folder and get the script running.

I tried this, but no result:


set this_folder to choose folder with prompt "Select source folder:" with multiple selections allowed
set target_folder to choose folder with prompt "Select backup folder:"


on adding folder items to this_folder after receiving these_items
	tell application "Finder" to duplicate these_items to target_folder
end adding folder items to

Any suggestions how to get the “adding folder items” function interact with the first part of the script where you can set the source and target folder?

Thanks a lot!,

Patrick

You may try :

set these_folders to choose folder with prompt "Select source folder:" with multiple selections allowed # I renamed the variable because it may contain several folders
set target_folder to choose folder with prompt "Select backup folder:"
tell application "Finder" to duplicate these_folders to target_folder

on adding folder items to this_folder after receiving these_items
	tell application "Finder" to duplicate these_items to target_folder
end adding folder items to

or

set these_folders to choose folder with prompt "Select source folder:" with multiple selections allowed  # I renamed the variable because it may contain several folders
set target_folder to choose folder with prompt "Select backup folder:"
my sharedCode(target_folder, these_items)

on adding folder items to this_folder after receiving these_items
	my sharedCode(this_folder, these_items)
end adding folder items to

on sharedCode(this_folder, these_items)
	tell application "Finder" to duplicate these_items to target_folder
end sharedCode

Yvan KOENIG running High Sierra 10.13.5 in French (VALLAURIS, France) lundi 18 juin 2018 16:43:09

Hi Yvan,

Thanks for your reply.
The first script does copy the source folder to the target folder but does not interact with the “adding folder items” function in the script. Do you know how to fix that?

The second script is giving me an error (variable these_items is not specified). It seems that it is specified, but I can’t see whats wrong.

Patrick