Copy folder to open window

I would like to automate the task of copying a folder (which contains a hierarchy of other folders) to an open window with just one click of the applescript in the window toolbar.

I have cobbled together some sort of script from other scripts but it doesn’t seem to work. I did manage to work out how to copy the folder to a specified folder but not to an open window which will determine where the folder needs to be copied to. I hope this makes sence and I’m sure it is easy to do but considering I’ve really only be looking into Applescript for a day it is not a surprise I can’t figure it out!!

Here is the Script so far:


try
	tell application "Finder" to set the source_folder to (folder of the front window) as alias
on error -- no open folder windows
	set the source_folder to path to desktop folder as alias
end try

tell application "Finder"
	copy the folder "Folder One:Folder Two" in the startup disk to (source_folder)
end tell

Many thanks in advance if you can help.

(Don’t worry I will be buying a book at the weekend, probably one of those “for Dummies” books knowing my lack of knowledge!!!)

You’re so very close.

There is one major problem with the script. In the line:

The Finder’s standard command for copying files is ‘duplicate’, not ‘copy’. (‘copy’ is used system-wide for clipboard manipulation).

Change this line to:

duplicate folder "Folder One:Folder Two" in the startup disk to source_folder

and I think you’ll be all set.

Excellent it worked, thanks!

There is one problem though. The folder I want to copy needs to ideally be on our server so everyone has access to the same information. I couldn’t get this to work over a network but it worked fine on my own mac. I read somewhere that you can only use AppleScript over a TCP/IP network and not over AppleTalk. I assume the script will need to change accordingly, something like:


duplicate folder "Folder1:folder2" of machine "10.0.0.00" to source_folder

We have a Snap server, weather this makes a difference I don’t know (we’ve just had plenty of problems with this server recently!)

I have figured out a way to work round this problem but it is not ideal.

Thanks again for your help.