At this point, this is an academic question. However, out of curiosity and for my own edification, I would love the answer to this question. Any help that anyone can offer would be appreciated.
I just wrote a script that does a backup of a specific folder to a specified server. It looks in a specific directory on a server and checks for a folder with the name based on the user name. If it is not there, it creates it. It then backs a specific folder up to that directory.
I needed to come up with the user name. I found this bit of code on the internet that works.
set the_user to the second word of (characters (offset of "Users" in path to ¬
preferences as string) through (length of (path to preferences as string)) of ¬
(path to preferences as string) as string)
This seemed to be over kill. I was thinking there has to be a easier way to return the user (account) name. With some playing around, I came up with this segment, that returned the user name:
tell application "System Events"
set the_user to name of current user as string
end tell
However, when I use this segment of code, I get an error later on in my script, and I can’t figure out why. If I just run this portion of the code, and I ask it to display the contents of the variable “the_user” both pieces of code return the same exact result. However, when I use the code in the actual script, I get an error message later on down the script. (It’s not concatenating the path correctly.)
Here is the full script. You should be able to parse the information you need from this script. Note, login information to the servers and IP addresses fake. Good luck. I hope this helps.
set startup_disk to path to startup disk as string
set NotesData_Path to startup_disk & "Applications:Lotus Notes:Data:"
tell application "Finder" -->Mount backup server
try
mount volume "afp://xxx:xxx@10.0.0.0/UserData"
end try
end tell
set the_user to the second word of (characters (offset of "Users" in path to ¬
preferences as string) through (length of (path to preferences as string)) of ¬
(path to preferences as string) as string)
-->return the login name of the computer
set backup_path to "UserData:MCE17:"
-->set variable to the backup path to the server
set user_folder_path to backup_path & the_user & ":"
-->Create path to user backup folder
try
alias user_folder_path
tell application "Finder"
duplicate folder NotesData_Path to user_folder_path replacing yes
end tell
--> file exists, go ahead and copy the data folder to the server. If the folder exists, replace it.
on error --> file doesn't exist, create a folder based on the user account name
-->copy the the data folder to that folder.
tell application "Finder"
make new folder at backup_path with properties {name:the_user}
delay 3
duplicate folder NotesData_Path to user_folder_path replacing yes
end tell
end try
delay 60
tell application "Finder" -->Dismount User Data Volume
activate
eject disk "UserData"
end tell