Hey everybody, I’m brand new to scripting and this may be a dumb question, but I’m trying to make a backup system for the office where i work. I need to basically make a script that gets the /Library/Mail/ folder so I can create a .zip file of it. The problem I’m having is that I need to give this to multiple people so I need to know what to put in for the file path to “get” so that it will not always be looking for “Users/brandonlynch/Library/Mail/”, but instead just know to look in the users home folder and get /Library/Mail/. Is that a clear enough description of my question? haha Sorry I’m REALLY green on this stuff. Thanks so much for any help you can give me on this one. I searched the forum and didn’t find quite the answer i was looking for.
Hi,
a portable version is
(path to home folder as Unicode text) & "Library:Mail:"
as string path or
alias ((path to home folder as Unicode text) & "Library:Mail:")
as alias
path to home folder points to the home folder of the current user
Thats awesome, Im heading in the right direction now, I just need to know what the appropriate method would be do this:
use that command in Automator’s “Run Applescript” action and then pass the specified folder to the next action.
heres how i want it to work if this info helps:
step 1: get the mail folder from the user;s home directory using the “run applescript” action
step 2: create an archive of the folder to be passed on to the next action.
I apologize for being so clueless, but any suggestions?
I would do the whole thing in AppleScript
set f to choose folder with prompt "choose a folder to save the zip-file"
set username to short user name of (system info)
set source to POSIX path of ((path to home folder as Unicode text) & "Library:Mail:")
set destination to POSIX path of f & "Mail_" & username & ".zip"
do shell script ("/usr/bin/ditto -c -k -rsrc --keepParent " & quoted form of source & " " & quoted form of destination)
you will asked for the destination folder, but of course you can also specify it in the script
Note: system info workes only in Tiger
Thanks, StefanK. Thats exactly what I need, the only problem is that I don;t want the computards that work here to have to pick out the mail folder, I just want it to grab the mail folder on whatever system it is and automatically make the zip file. Could you tell me how to get the mail folder without the prompt?
EDIT: sorry I misread the script before i replied. Thank you Stefan for all your help, you have saved my life.
then you must specify the destination folder in the script e.g. the documents folder
set username to short user name of (system info)
set source to POSIX path of ((path to home folder as Unicode text) & "Library:Mail:")
set destination to POSIX path of ((path to documents folder as Unicode text) & "Mail_" & username & ".zip")
do shell script ("/usr/bin/ditto -c -k -rsrc --keepParent " & quoted form of source & " " & quoted form of destination)
or a folder on an external volume
set destination to ("/Volumes/BackupVolume/Mail_" & username & ".zip")
Note: Here the slash separated POSIX path is used directly. A POSIX path to an external volume starts with /Volumes/VolumeName/…
Unimportantly (but I just thought I’d mention it :)), it’s also possible to get ‘path to’ itself to return the user’s Library folder:
(path to library folder from user domain as unicode text) & "Mail:"
I am modifying whatwe worked on in this post, but it’s not working and I can’t understand why.
set source to POSIX path of ((path to home folder as Unicode text) & "Library:Mail:")
set destination to ("/Volumes/Bootintosh/Mail_backup.zip")
do shell script ("usr/bin/ditto -c -k -rsrc --keepParent " & quoted form of source & "" & quoted form of destination)
it just comes back with
“ditto: No destination
Usage: ditto []src[…src]dst”
my brain just really doesn’t seem cut out for scripting.
Hi,
in the shell script line between source and destination must be a space character, not an empty string.
This syntax helps
.
do shell script ("usr/bin/ditto -c -k -rsrc --keepParent " & quoted form of source & space & quoted form of destination
.
thanks, for that. That works.
Problem is when i run the script, script editor freezes after it’s done and if i save it as an application, the application freezes after it’s done. So in short, the script does the job, but doesn’t quit when it’s done.
Some weeks ago I wrote an all-purpose subroutine to compress files and folders with ditto.
My script has never freezed during the extensive testing phase