Hi all
Although I learned a lot from all the posts here, now I have a problem and can’t solve it… so here comes my first post, hope you guys can help.
I have several Macs, one of them works as a ‘Server’ so I can use Spotlight on his document from all other Macs (which I can’t if stored on my NAS). On a daily basis I wanna copy 2 Folders from my Mac Server → NAS, I start the script with crontab, that works fine.
To let the NAS ‘sleep’ when not used, I don’t mount the drive permanently. So in my script I wanna do the following steps :
- Mount the drive from NAS
- Delete the 2 Folder on my NAS
- Copy the 2 folder from Mac → NAS
- Unmount the drive
It used to work with this script (I know, no error handling)… but suddenly it doesn’t anymore (maybe a firmware upgrade on my NAS). Today it works as long as the folders do not exist on the NAS, if they do, the script can’t delete them and stops… so basically the script works only once… after that I get sometimes errors 10004, 1728 because it can’t delete the folders (seems to be a permission problem)
-- 1x pro Tag muss die ganze Rechnungsablage und der ganze Rechnungseingang
-- als Sicherheitskopie aufs NAS kopiert werden
try
tell application "Finder"
-- Externes Volume mounten
mount volume "smb://<name>:<pw>@<correct IP>/Dokumente"
--mount volume "smb://<correct IP>/Dokumente"
-- zuerst löschen wir die Ordner Rechnungseingang und Ablage auf dem NAS
delete folder "Dokumente:Gemeinsam:aa_Rechnungseingang:"
delete folder "Dokumente:Gemeinsam:Ablage:"
-- Dann werden die Inhalte von hier lokal raus aufs NAS in die richtigen Ordner kopiert
duplicate folder "Snow Leopard:Users:Giusi:Documents:aa_Rechnungseingang:" to folder "Dokumente:Gemeinsam:"
duplicate folder "Snow Leopard:Users:Giusi:Documents:Ablage:" to folder "Dokumente:Gemeinsam:"
-- Externes Volume wieder abhängen
tell application "Finder" to eject disk "Dokumente"
end tell
end try
Now I tried a couple of different things but I can’t figure out what I’m doing wrong. Here the newest version, I even changed from smb to afp… This script runs once (if I clean the NAS first), it mounts the drive, tries to delete, then copies everything I want over to the NAS and then unmounts the drive… the second time it runs, I get errors because he can’t delete the folders and stops.
if "Dokumente" is not in (do shell script "ls /Volumes") then
try
mount volume "afp://<name>:<pw>@<correct ip>/Dokumente"
on error
return -- abort the script
end try
end if
try
tell application "Finder"
if "aa:Rechnungseingang" is in (do shell script "ls /Volumes/Dokumente/Gemeinsam") then
do shell script "/bin/rm -r /Volumes/Dokumente/Gemeinsam/aa_Rechnungseingang"
end if
if "Ablage" is in (do shell script "ls /Volumes/Dokumente/Gemeinsam") then
do shell script "/bin/rm -r /Volumes/Dokumente/Gemeinsam/Ablage"
end if
-- Dann werden die Inhalte von hier lokal raus aufs NAS in die richtigen Ordner kopiert
duplicate folder "Snow Leopard:Users:Giusi:Documents:aa_Rechnungseingang:" to folder "Dokumente:Gemeinsam:"
duplicate folder "Snow Leopard:Users:Giusi:Documents:Ablage:" to folder "Dokumente:Gemeinsam:"
-- Externes Volume wieder abhängen
tell application "Finder" to eject disk "Dokumente"
end tell
end try
Interesting is that it
- can mount the drive
- can’t delete the first folder
- can delete the second folder
- fails to copy the first folder with error 15267 (Folder exists) and stops
- then it can’t unmount the drive as it probably leaves the script with the step described above
I’m sorry if this go too long but I would really appreciate a hint/help in this matter.
thanks
oraguru
Model: Mac Mini
AppleScript: 2.2.1
Browser: Chrome 25
Operating System: Mac OS X (10.7)