This is the second or third time in the last ten years that I have used applescript, therefore I am no expert. I hope this isnt a stupid question, I have read around the subject before posting.
I have the following line of code in my script.
duplicate every item of folder “shake_scripts” of disk “Video” to folder “shake_backup” in disk “Mac HD” with replacing
However, even though I have “with replacing” at the end, the script is still generating an error if it tries to overwrite previously existing folders in the destination. I can copy the contents of my directory to an empty folder with no problem but if i run the script again, it will not overwrite the folders, just the files. I simpl want to regularly back up the entire contents of one folder to another, it seems a very simple thing to achieve.
Model: G5
AppleScript: 1.93
Browser: Safari 312
Operating System: Mac OS X (10.4)
This is the script I came up with on my mac. It seems to work alright. It may be a problem with your file path designation. I used the Finder in this script. You don’t have to activate it (and quite possibly not even reference it). Anyway here it goes:
tell application “Finder”
activate
select every file of folder “Test” of folder “Desktop” of folder “admin2” of folder “Users” of startup disk
duplicate selection to folder “ScriptTest” of folder “Desktop” of folder “admin2” of folder “Users” of startup disk with replacing
end tell
You’ll have to define your file path to fit your computer. Hope this helps some.
PreTech
Browser: Safari 125.12
Operating System: Mac OS X (10.4)
The thing is, i dont want to copy every file to another place with replacing, i want to copy every item. IE: all files and folders in that directory and any files and folders in subdirectories contained within.
the following line works fine:
duplicate every file of folder “shake_scripts” of disk “Video” to folder “shake_backup” in disk “Mac HD” with replacing
what doesnt work is:
duplicate every item of folder “shake_scripts” of disk “Video” to folder “shake_backup” in disk “Mac HD” with replacing
it seems to me that this is a very common requirement (it is the basis of any kind of automatic backup script) so someone must have come across this problem before.
Until Jonn tells us what’s really going on you can do this:
tell application "Finder"
delete items of folder "Disk:Users:Documents:BackupF:"
end tell--Close the tell block
tell application "Finder"
duplicate items of folder "Disk:Users:Documents:Tester:" to folder "Disk:Users:Documents:BackupF:"
end tell
If you can’t find the syntax, go the “hardwire” route. If you enclose “delete items of the folder” in a separate tell block, deleting is completed before the next tell block, “duplicate items”.
I assume your writing the paths as above and not as
folder “shake_scripts” of disk “Video” to folder “shake_backup” in disk “Mac HD”
-something like copy … “Video:shake_scripts:” to “Mac HD:shake_backup:”
SC
Properties are basically special variables. They must be declared at the top of a script or script object. Properties retain their value until the script is recompiled*. The scope of a property is as follows:
You can test this if you’d like. Save both of these scripts as applications, and try running them both a few times.
set counter to 1
display dialog counter buttons "OK" default button 1
set counter to counter + 1
property counter : 1
display dialog counter buttons "OK" default button 1
set counter to counter + 1
The first script will always say “1”, but the second will increase every time. (If the second gets recompiled [read: edited], it will go back to the original value of the property.)
Well, that’s properties in a nutshell. [You can probably stop reading now.]
I’ll point out that I sometimes use properties when I have no real reason to. Here’s an example (a piece of my alarm clock):
property theVolume : 70
property thePlaylist : "Wake Up"
set volume without output muted
set volume output volume theVolume
tell application "iTunes"
activate
play playlist thePlaylist
end tell
In this example, I don’t need to use propeties (but there’s nothing wrong with that). I could use a “set” command instead, or I could just hard code the values [that is, get rid of the variables and just say ‘play playlist “Wake Up”’]. I would recommend using properties or variables so the values can be easily changed. The fact that I use properties (when their features aren’t needed) is just a personal preference.
I thought I would point that out, because I wouldn’t want anyone getting confused as to why I’m using properties… [OK, you can definately stop reading now. :)]
So it is not correct to use the following because it will only set the variable at the time of compiling?
if the weekday of (current date) is Sunday then
property backupFolder : quoted form of "/sunday_backup"
end if
if the weekday of (current date) is Monday then
property backupFolder : quoted form of "/monday_backup"
end if
Do i do it like this instead? Is the syntax correct?
if the weekday of (current date) is Sunday then
set backupFolder to quoted form of "/sunday_backup"
end if
if the weekday of (current date) is Monday then
set backupFolder to quoted form of "/monday_backup"
end if
Do I put all this at the top of the script before the on idle and tell application “finder”?