How to choose destination folder within in Folder Actions

Hello, I’m using this script as an folder action. When a file is dropped on the specific folder the action is triggered and is will duplicate the file to a destination folder.

This is the script:


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

Pretty simple end it works fine.

But I wan’t to set the destination folder by a “choose folder command” , see script below. But now everytime a file is dropped on the folder I have to choose the destination folder for it over and over again. Is there a way to set the destination folder once? Which will be used by every file dropped on the folder?


on adding folder items to this_folder after receiving these_items 
set target_folder to choose folder with prompt "Select backup folder:"
tell application "Finder" to duplicate these_items to target_folder 
end adding folder items to

Like a persistent variable?

property destinationFolder : missing value

on adding folder items to this_folder after receiving these_items 
	if not (exists destinationFolder) then set destinationFolder to with prompt "Select backup folder:"
tell application "Finder" to duplicate these_items to destinationFolder 
end adding folder items to

When you install the script on a new machine or (re)compile the code the user will be prompted to choose a folder. In consecutive runs the user will not be prompted to choose a folder.

Thanks! This seems to what i’m looking for. I recomposed the script a bit because the “choose folder” command was missing. But when I run it like a folder action nothing happens when i’m putting a file in the targeted folder. It seems that it is not triggering te action. Can you see what’s wrong?

This is the script I tried:


property destinationFolder : missing value

on adding folder items to this_folder after receiving these_items 
	if not (exists destinationFolder) then set destinationFolder to choose folder with prompt "Select backup folder:"
tell application "Finder" to duplicate these_items to destinationFolder 
end adding folder items to