duplicate file or folder

Hi all

Got some old code for Excel 2011 that use the VBA macscript function to run some AppleScript.

In Excel 2016 and up we must use the applescripttask VBA function now to run AppleScript that is in a separate script file in most situations and that i want to avoid so I want to see if Shell can help me because this will work in some situations in the VBA macrscript function.

Problem I am bad with Shell in AppleScript and I hope you guys can give me some example script so I can see if I can get it working from VBA.

Greetings from the Netherlands

To provide a really useful script, we need more detail on what it should do. However, just for testing purposes with VBA, I have included two scripts below. They both copy an existing file named “Test File.txt” from your documents to your desktop folder. The first script uses the “cp” command and appears to be what you want; the second script uses the Finder.

set sourceFile to ((path to documents folder as text) & "Test File.txt") as alias
set sourceFile to POSIX path of sourceFile
set destinationFolder to POSIX path of (path to desktop)

do shell script "cp " & quoted form of sourceFile & space & quoted form of destinationFolder
set sourceFile to ((path to documents folder as text) & "Test File.txt") as alias
set destinationFolder to (path to desktop)

tell application "Finder"
	duplicate sourceFile to destinationFolder with replacing
end tell

It’s probably a good idea to try these first in Script Editor to make sure they work OK–they did on my computer. Also, VBA may have trouble with alias and POSIX path, in which case the specific path should be tried (e.g. /Users/Peavine/Desktop/)

Hi Peavine

Thanks for your reply and time , got something to test this weekend, I will reply back with my results.

Hi Peavine

No luck when trying it with the old Macsscript function with Shell, we must use VBA applescripttask in Excel 2016 and higher for this. I like to ask you two things, do you have an example to copy/ duplicate a folder with shell for me and add a date/time to it and can you tell me a good reference to learn shell, from what I read Shell is faster then talk to finder in AppleScript. Maybe a good book or so ?

thanks for your time

I’m sorry to hear those scripts didn’t work.

The following script copies the contents of sourceFolder to destinationFolder, and destinationFolder is created if it doesn’t exist. You don’t mention how you want the date formatted, so I kept this simple.

set sourceFolder to POSIX path of (choose folder)

set destinationFolder to POSIX path of (choose folder)
set destinationFolder to destinationFolder & "Backup on " & ((current date) as text)

do shell script "ditto " & quoted form of sourceFolder & space & quoted form of destinationFolder

I can’t recommend any books on using the shell. In this particular instance, the ditto man page is quite informative, and, FWIW, the following is a technical note on the do-shell-script command:


Thanks Peavine for your reply, I go test more and read the info in the link you posted and create some VBA examples with it for my site. Win Excel is so much easier to automate with scripting.filesystemobject.

Have a great day