Script for copying files to drop boxes of other Macs
apple Verified ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
I don't know much about scripts as yet, but for daily backup purposes
I would like to copy all new or modified files from various folders
to the drop boxes of two other Macs (like the old DOS command XCopy)
and then reset the "modified attributes" (is there something like that at all?)
of these files.
A script could do this without the need to always find and select these files
and to always confirm the messages "You can put items into “Drop Box”,
but you won’t be able to see them. Do you want to continue?".
Thanks!
15 replies
Sign in or join Beachball Help to reply.
- 0
KOENIG Yvan ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
To build a script, I must know the pathnames of the source folders and those of the destination ones.
You may send them directly to my mailbox.
Click my bluename to get my address.Yvan KOENIG (VALLAURIS, France) mardi 15 décembre 2009 19:08:29
- 0
coxorange ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Thank you! It's no secret 😉 so I can post it here. It might also be helpful for others:
Path to source folders:
"/Users/home/Documents/Pages/current/"
"/Users/home/Documents/Databases/current/"+(and more lines like this, which I could amend later)+
Path to destination folders:
"/cr1’s iMac.
afpovertcp.tcp.local/cr1's%20Public%20Folder/Drop Box/backup/Documents/Pages/current/"
"/cr1’s iMac.
afpovertcp.tcp.local/cr1's%20Public%20Folder/Drop Box/backup/Documents/Databases/current/"+(and more lines like this, which I could amend later)+
and
"/cr2’s iMac.
afpovertcp.tcp.local/cr1's%20Public%20Folder/Drop Box/backup/Documents/Pages/current/"
"/cr2’s iMac.
afpovertcp.tcp.local/cr1's%20Public%20Folder/Drop Box/backup/Documents/Databases/current/"+(and more lines like this, which I could amend later)+
(If target files with the same name already exist (older versions) they could simply be overwritten.)
Lots of thanks!
- 0
KOENIG Yvan ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
These pathnames must be stored somewhere.
I think of two soluces.(1) lists embedded in the script
(2) lists embedded in one text file :
/Users/home/Documents/Pages/current/
/cr1’s iMac.
afpovertcp.tcp.local/cr1's%20Public%20Folder/Drop Box/backup/Documents/Pages/current/
/cr2’s iMac.
afpovertcp.tcp.local/cr1's%20Public%20Folder/Drop Box/backup/Documents/Pages/current/
/Users/home/Documents/Databases/current/
/cr1’s iMac.
afpovertcp.tcp.local/cr1's%20Public%20Folder/Drop Box/backup/Documents/Databases/current/
/cr2’s iMac.
afpovertcp.tcp.local/cr1's%20Public%20Folder/Drop Box/backup/Documents/Databases/current/
…My preferred is version 2 but I wish to know your advice.
I'm unaware of a "modified attributes" property.
There is one when the document is open by an application but it is reset to not_modified when the document is saved.Yvan KOENIG (VALLAURIS, France) mercredi 16 décembre 2009 14:00:54
- 0
coxorange ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
You're right, it's clearer to have an extra text file.
There is one when the document is open by an application
but it is reset to not_modified when the document is saved.That's exactly what we need! Only files which have been opened
(new ones + modifies ones + opened ones) shall be copied,
and after saving to both targets these attributes should be reset
to avoid saving these files in the future in case they haven't
at least been opened again.Thanks so far! 🙂
- 0
KOENIG Yvan ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
It seems that my English was not clear.
The modified attributes is available as far as the document is open in the app.
If we save it, the attribute is cleared and nobody will be aware of it.
The only way to know that a document was edited is to compare the modification date (or compare the content itself).
I assume that comparing the modification dates will be sufficient.Are the two external volumes guaranteed to contain exactly the same files ?
If they are, we may compare the dates only once.Are the listed folders supposed to contain only documents or are there allowed to contain subfolders ?
Yvan KOENIG (VALLAURIS, France) mercredi 16 décembre 2009 16:36:22
- 0
coxorange ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
The modified attributes is available as far as the document is open in the app.
If we save it, the attribute is cleared and nobody will be aware of it.Oh, now I see...
The only way to know that a document was edited is to compare the modification
date (or compare the content itself). I assume that comparing the modification
dates will be sufficient. Are the two external volumes guaranteed to contain exactly
the same files ? If they are, we may compare the dates only once.Yes that's fine.
Are the listed folders supposed to contain only documents or are there allowed
to contain subfolders ?Subfolders too. I'm afraid that means more loops...?
- 0
KOENIG Yvan ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Here is a short skeleton which doesn't treat subfolders.
May you check if it do what you want ?
--
property sourceFolder : "/Users/home/Documents/Pages/current/"
property destFolder : "/cr1’s iMac.afpovertcp.tcp.local/cr1's%20Public%20Folder/Drop Box/backup/Documents/Pages/current/"
on run
tell application "System Events"
set dest_folder to path of folder destFolder
set listeSource to path of disk items of folder sourceFolder
repeat with sf in listeSource
if visible of disk item sf then
tell disk item sf
set sn to name
set smd to modification date
end tell
if exists disk item sn of folder destFolder then
set needCopy to modification date of disk item sn of folder destFolder is not smd
else
make new file at end of folder destFolder with properties {name:sn}
set needCopy to true
end if -- exists disk item
if needCopy then my copyFile(sf, dest_folder)
end if -- visible …
end repeat
end tell -- System Events
end run
on copyFile(sourceFile, targetFolder) (*
sourceFile is the path to the source file as text,
dest_folder is the path to the destination folder as text
newFileName is the name of the file as text
*)
tell application "Finder"
duplicate file sourceFile to folder targetFolder with replacing
end tell
end copyFile
--Yvan KOENIG (VALLAURIS, France) mercredi 16 décembre 2009 18:33:43
- 0
twtwtw ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
this sounds like you want to use rsync script - something like the following (as you'd run it in terminal, though you could set up an applescript or launchd item to do the same):
rsync -a ~/Documents/ '/cr1’s iMac.afpovertcp.tcp.local/cr1's Public Folder/Drop Box/backup/' -filter='+ Pages/' -filter='+ Databases/' -filter='+ */current/' -filter='- *'
rsync -a ~/Documents/ '/cr2’s iMac.afpovertcp.tcp.local/cr2's Public Folder/Drop Box/backup/' -filter='+ Pages/' -filter='+ Databases/' -filter='+ */current/' -filter='- *'add {color:green}-filter='+ foldername/'{color} terms for every folder with a 'current' subfolder you want to back up
just a unix note: file paths with spaces need to be enclosed in quote. so {color:green}/cr2’s iMac.
afpovertcp.tcp.local/cr2's Public Folder/Drop Box/backup/{color} becomes {color:green}'/cr2’s iMac.
afpovertcp.tcp.local/cr2's Public Folder/Drop Box/backup/'{color} (enclosed in sinle-quotes, with backslashes to escape the single-quotes that are part of the path)> - 0
coxorange ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
I tried it, but received an
Apple Script Error
System Events got an error: Can’t get folder "/cr1’s iMac.
afpovertcp.tcp.
local/cr1's%20Public%20Folder/Drop Box/backup/Documents/Pages/current/".Maybe the 'current' folder in the other iMac's Drop Box isn't accessed correctly?
From the iMac where the script is running, I can't look deeper than into its Drop Box level.
'Get Info' brings the following information about its 'Drop Box':
Where: /Volumes/cr1's Public Folder
Server: afp://cr1’s iMac.
afpovertcp.tcp.local/cr1's%20Public%20Folder/Drop BoxMaybe both lines must be combined...?
- 0
KOENIG Yvan ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
I apologize but I never use networked machines so I can't test a script based upon rsync.
It seems that the skeleton would be:
property sourceFolder : "/Users/home/Documents/Pages/current/"
property destFolder : "/cr1’s iMac.
afpovertcp.tcp.local/cr1's%20Public%20Folder/Drop Box/backup/Documents/Pages/current/"on run
do shell script "rsync -a " & sourceFolder & space & destFolder
end runYvan KOENIG (VALLAURIS, France) mercredi 16 décembre 2009 20:12:43
- 0
twtwtw ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
well, if you want to do it from applescript, use this:
property sourceFolder : "~/Documents/"
property destFolderList : {"/cr1’s iMac.afpovertcp.tcp.local/cr1's Public Folder/Drop Box/backup/", "/cr2’s iMac.afpovertcp.tcp.local/cr2's Public Folder/Drop Box/backup/"}
property folderList : {"Pages", "Databases"}
on run
set theText to "rsync -a " & quoted form of sourceFolder
repeat with thisFolder in destFolderList
set cmd to theText & " " & quoted form of thisFolder
repeat with thisFold in folderList
set cmd to cmd & " -filter='+ " & thisFold & "/'"
end repeat
set cmd to cmd & "-filter='+ */current/' -filter='- *'"
do shell script cmd
end repeat
end run - 0
coxorange ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Thanks for your suggestion.
You are right - it's a kind of synchronisation.
Unfortunately I can't translate this into a script. - 0
coxorange ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Thanks, just found your other message.
- 0
coxorange ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Thanks, I tried it. Here's the result:
AppleScript Error
rsync: link_stat "/~/Documents/." failed: No such file or directory (2)
rsync: mkdir "/cr1#342#200#231s iMac.
afpovertcp.tcp.local/cr1's Public Folder/Drop Box/backup" failed: No such file or directory (2)
rsync error: error in file IO (code 11) at /SourceCache/rsync/rsync-37.3/rsync/main.c(544) [receiver=2.6.9]
rsync: connection unexpectedly closed (8 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at /SourceCache/rsync/rsync-37.3/rsync/io.c(452) [sender=2.6.9]Could this...
http://discussions.apple.com/message.jspa?messageID=10749285&tstart=0
... be the reason? - 0
twtwtw ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
I don't know what you're pointing to with that link (since it seems to be a link back to this thread). however...
coxorange wrote:
rsync: link_stat "/~/Documents/." failed: No such file or directory (2)
This means it's not expanding the ~ correctly. use the full path - /Users/whatever/Documents - instead
coxorange wrote:
rsync: mkdir "/cr1#342#200#231s iMac.
afpovertcp.tcp.local/cr1's Public Folder/Drop Box/backup" failed: No such file or directory (2)This probably means that the path to the backup folder isn't specified correctly. it may have something to do with the way 'quoted form of' quotes things (your path name has spaces, single quotes, and html entities in it, which goofs things up from a unix perspective - is that what it really looks like?). you could try quoting it in the property line and getting rid of the 'quoted form of' bit:
property destFolder : "/cr1’s iMac.
afpovertcp.tcp.local/cr1's Public Folder/Drop Box/backup/Documents/Pages/current/"