Hi there Anthony,
This is how I would possibly do it...
As a learning exercise this is how my brain works...
...as CAS said using variables is the best way to go, but whilst you are still learning it can confuse you...
Break down what you are trying to do into sections...
I like to show people this way...
Section 1
--check that the Backup drive is plugged in !
--for this test mine is called "1GBUSB"
tell application "Finder"
if exists disk "1GBUSB" then
beep 3
end if
end tell
The above script checks if the drive is there, if it is it will then do your commands in this instance it's just do 3 beeps.
I find this is the best way for someone learning to get instant feedback on whether it works !
So now that we know that works, build the next bit.
Section 2
replace "1GBUSB" with your external drive name...
tell application "Finder"
if exists disk "1GBUSB" then
beep 3
--now run the next bit
--do your delete
delete (every folder in disk "1GBUSB" whose name does not contain "downloads")
end if
end tell
It works doesn't it !!!
Now the next bit,
Section 3
We'll add in the path for your folders, again we'll not use variables this time, just so that we can see whats happening...
tell application "Finder"
if exists disk "1GBUSB" then
beep 3
--do your delete
delete (every folder in disk "1GBUSB" whose name does not contain "downloads")
--now run the next bit
duplicate folder "movies" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
--as you can see this is nice plain English and you can see exactly what is happening !
--I created an empty folder called movies for testing
--if this folder is already there it will get overwritten !
end if
end tell
Now we can add in the other folders...
Section 4
tell application "Finder"
if exists disk "1GBUSB" then
beep 3
delete (every folder in disk "1GBUSB" whose name does not contain "downloads")
duplicate folder "movies" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
duplicate folder "pictures" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
duplicate folder "music" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
duplicate folder "documents" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
end if
end tell
Now run that...
Section 5
I presume that it will give you timeouts...
So to address timeouts we use the 'with timeout' statement...
tell application "Finder"
if exists disk "1GBUSB" then
beep 3
delete (every folder in disk "1GBUSB" whose name does not contain "downloads")
--60 seconds = 1 minute..1800 Seconds = 30 minutes amend as required...
with timeout of 1800 seconds
duplicate folder "movies" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
duplicate folder "pictures" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
duplicate folder "music" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
duplicate folder "documents" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
end timeout
end if
end tell
That should now run nicely, whilst you are testing it use dummy folders with less data in !
You'll have to change the timeout depending on how much data you have in your folders...
Section 6
I would wrap the "duplicates" in a try statement then if for any reason one fails it would move onto the next one...
So the script would now look like...
tell application "Finder"
if exists disk "1GBUSB" then
beep 3
delete (every folder in disk "1GBUSB" whose name does not contain "downloads")
--60 seconds = 1 minute..1800 Seconds = 30 minutes amend as required...
with timeout of 1800 seconds
try
duplicate folder "movies" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
end try
try
duplicate folder "pictures" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
end try
try
duplicate folder "music" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
end try
try
duplicate folder "documents" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
end try
end timeout
end if
end tell
So now if the folder "pictures" was not in the folder "ant" it wouldn't stop the script, the rest of the folders would still get backed up.
That should all be working...
Section 7
Now, the empty trash.
You can add this into your script, but it may be best to leave it off till you are happy to use it.
Imagine if while working on this script you got a few names wrong...all your pictures could end up in the trash and deleted, very easily.
I've added the empty into the script, but have 'commented it out', so if you want it in just delete the --
We can also take out the beeps now if we want..
tell application "Finder"
if exists disk "1GBUSB" then
delete (every folder in disk "1GBUSB" whose name does not contain "downloads")
--60 seconds = 1 minute..1800 Seconds = 30 minutes amend as required...
with timeout of 1800 seconds
try
duplicate folder "movies" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
end try
try
duplicate folder "pictures" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
end try
try
duplicate folder "music" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
end try
try
duplicate folder "documents" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
end try
end timeout
end if
end tell
Section 8
Add in the Shut down command !
tell application "Finder"
if exists disk "1GBUSB" then
delete (every folder in disk "1GBUSB" whose name does not contain "downloads")
--60 seconds = 1 minute..1800 Seconds = 30 minutes amend as required...
with timeout of 1800 seconds
try
duplicate folder "movies" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
end try
try
duplicate folder "pictures" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
end try
try
duplicate folder "music" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
end try
try
duplicate folder "documents" of folder "ant" of folder "users" of startup disk to disk "1GBUSB"
end try
end timeout
end if
end tell
tell application "System Events"
shut down
end tell
I would leave the Shut down out whilst you are testing, otherwise it will be a real pain...
hope that helps
Regards
Ric