Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

blueflash99

macrumors member
Original poster
Aug 30, 2011
31
1
I have searched everywhere and just cannot get this right in an apple script
I have an external had drive called G_5TB attached to my mac running Catalina.
I have a folder on this drive "Manual Backups". I want to create a subfolder "Manual backup todaysdate".
I have
Code:
set destf to "Manual backup " & date string of (current date)
set destfpath to "/Volumes/G_5TB_general/Manual Backups/"

tell application "Finder"
    make new folder at "destpath" & "destf"
end tell

I have tried many variations of this but cannot get the syntax right.
Can anyone set me straight please?
 
Last edited:
I'm no AppleScript expert, however, you say your drive is called "G_5TB" but you are targeting a disk called "G_5TB_general", what's up with that?
 
Firstly Finder requires an AppleScript alias type in order to create the new Folder.
Your just passing it a String with the code "destpath" & "destf".
Also your String representation of the path is a Posix style path with "/" separators, when an HFS style path is required with ":" separators.
So try something like the below example.

Code:
set destf to "Manual backup " & date string of (current date)
set destpath to "Volumes:G_5TB_general:Manual Backups:"

tell application "Finder"
    try
        make new folder at (destpath as alias) with properties {name:destf}
    on error
        display dialog "Error! The hard drive folder named," & return & destpath & return & "Cannot be found."
    end try
end tell


Or if you insist on using a Posix style path for your "destpath" variable.

Code:
set destf to "Manual backup " & date string of (current date)
set destpath to "/Volumes/G_5TB_general/Manual Backups/"

tell application "Finder"
    try
        make new folder at (POSIX file destpath as alias) with properties {name:destf}
    on error
        display dialog "Error! The hard drive folder named," & return & destpath & return & "Cannot be found."
    end try
end tell

Also you should use some error checking code, just in case you external drive is not plugged in, or any folder your trying to write to does not exist.
 
Last edited:
  • Like
Reactions: barbu
Thanks for your reply Mark, I created the folder, no probs.
As you might have guessed, I am still finding my way with scripting.
Having created the folder, I would now like to use rsync to backup files to it. I have a folder on
/Volumes/homes/CG_backups/Scripts and would like to copy all subfolders and files from there to the
newly created destination folder.
I have
Code:
set tempVar to do shell script "rsync -ahv   /Volumes/homes/CG_backups/Scripts destination"

but can't get the syntax for "destination" to point to the newly created folder "Volumes:G_5TB_general:Manual Backups: "Manual backup " & date string of (current date)
I guess I am mixing up POSIX and HFS style paths.
 
your rsync command will likely need to escape the space you have:

"rsync -ahv /Volumes/homes/CG_backups/Scripts\ destination"
 
Yes barbu is correct, if your source or destination paths have any spaces or invalid characters, then you must escape them in the "do shell script" command.
In AppleScript you do this by using the "quoted form of" keywords like this below.

Code:
set tempVar to do shell script "rsync -ahv " & quoted form of "/Volumes/homes/CG_backups/Scripts destination"

I've never used "rsync", so I cant tell or help you if your using it correctly, having never used it before myself.
But my understanding is that you have to supply source and destination locations.
And as for the "-ahv" parameters, again I can't tell if there correct.

If your unsure about "rsync" yourself, then type "man rsync" into a terminal window for guidance.
But for any string you pass to a "do shell script" from AppleScript, always use the "quoted form of" keywords.
 
  • Like
Reactions: barbu
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.