Saturday, August 8, 2020

#1 2020-07-31 07:19:20 am

rdb1968
Member
From:: Netherlands
Registered: 2012-02-15
Posts: 137
Website

duplicate file or folder

Hi all

Got some old code for Excel 2011 that use the VBA macscript function to run some AppleScript.
http://www.rondebruin.nl/mac/mac028.htm

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


Ron de Bruin Excel Automation
http://www.rondebruin.nl

Offline

 

#2 2020-07-31 09:39:56 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 567

Re: duplicate file or folder

rdb1968 wrote:

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.



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.

Applescript:

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

Applescript:

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/)

Last edited by peavine (2020-08-01 07:40:17 am)


2018 Mac mini - macOS Catalina

Offline

 

#3 2020-07-31 04:23:22 pm

rdb1968
Member
From:: Netherlands
Registered: 2012-02-15
Posts: 137
Website

Re: duplicate file or folder

Hi Peavine

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


Ron de Bruin Excel Automation
http://www.rondebruin.nl

Offline

 

#4 2020-08-03 04:21:16 am

rdb1968
Member
From:: Netherlands
Registered: 2012-02-15
Posts: 137
Website

Re: duplicate file or folder

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


Ron de Bruin Excel Automation
http://www.rondebruin.nl

Offline

 

#5 2020-08-03 07:29:19 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 567

Re: duplicate file or folder

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.

Applescript:

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:

https://developer.apple.com/library/arc … index.html

Last edited by peavine (2020-08-03 03:02:19 pm)


2018 Mac mini - macOS Catalina

Offline

 

#6 2020-08-03 09:00:10 am

rdb1968
Member
From:: Netherlands
Registered: 2012-02-15
Posts: 137
Website

Re: duplicate file or folder

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


Ron de Bruin Excel Automation
http://www.rondebruin.nl

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)