AppleScript Help Please

Trying to teach myself AppleScript and I’m starting with the very basics. Did a search both here and via Google and really didn’t come up with anything I could understand.


For backups I use ChronoSync and it has the ability to run a script pre/post backup. I have created an Automator application that will copy a number of files/folders prior to the backup by ChronoSync. But, the ChronoSync “help”information states:


“In the "Scripts" section, you can set up scripts to be executed either before or after the synchronization runs. ChronoSync can execute AppleScript files, shell script files and applications as a pre- or post- sync 'script'. In the case of applications, ChronoSync will simply launch the application but will not wait for it to terminate. ChronoSync will patiently wait for the scripts to finish executing before continuing. Check the appropriate box based on when you want a script to run and then select the “Choose...” button to select the script that you would like to run.”


So, what I’d like to do is write a script that will copy files from one folder to another, and to make it easy to test, I’ve created two folders on the desktop. Test1 and Test2. Test1 has files, Test2 does not.


If someone could come up with the needed AppleScript for me I’d be appreciative, and hopefully be able to use that as a template for the future.

MacBook Pro 13″, macOS 12.6

Posted on Jul 8, 2023 10:46 AM

Reply
Question marked as Top-ranking reply

Posted on Jul 10, 2023 12:26 PM

I was sent these scripts and they work perfectly. Thought I'd post them here so they could help others.


This works for files:


tell application id "com.apple.Finder" to duplicate file POSIX file ¬

"/Users/homer/Desktop/Test1/Test.pages" to the folder ¬

POSIX file "/Users/homer/Desktop/Test2" with replacing


This works for folders:


tell application id "com.apple.Finder" to duplicate folder POSIX file ¬

"/Users/homer/Desktop/Test1" to the folder ¬

POSIX file "/Users/homer/DesktopTest2" with replacing


Similar questions

3 replies
Question marked as Top-ranking reply

Jul 10, 2023 12:26 PM in response to MargeHomer

I was sent these scripts and they work perfectly. Thought I'd post them here so they could help others.


This works for files:


tell application id "com.apple.Finder" to duplicate file POSIX file ¬

"/Users/homer/Desktop/Test1/Test.pages" to the folder ¬

POSIX file "/Users/homer/Desktop/Test2" with replacing


This works for folders:


tell application id "com.apple.Finder" to duplicate folder POSIX file ¬

"/Users/homer/Desktop/Test1" to the folder ¬

POSIX file "/Users/homer/DesktopTest2" with replacing


Jul 10, 2023 1:59 PM in response to ku4hx

ku4hx, Thank you for the link. It will help me to understand what parts of the script serve what functions (I have no idea how I would even create one of those dashes with the drop down on the far right). One of the first mistakes I made when sent the above scripts was thinking that AppleScript, like rsync, would need to have paths to the files/folders copied over from Terminal. Once I figured out that that was not the case, a simple "Option" key with a right-click to copy the path, and I was able to make the scripts work with files/folders buried deep in my user folder. Again, thanks, will make for good reading.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

AppleScript Help Please

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.