OK Rob, you have been a great help. Let’s see if you can see what I’m doing here.
This script is working great, except for one thing. After I select the home folder, I try to get the size of it using that script you sent along. Problem is, it works ok if I manually enter the path to the user, but not when I try to use a property. The problem is with the line:
set byteSize to (info for alias theHome)
.
It works if I put the following, but of course, I need it to reference “theHome”
set byteSize to (info for alias "HD:Users:staff")
Here is the full script so far:
set excluded_ to {"Network"}
set volumes_ to (path to startup disk as text) & "Volumes"
tell application "Finder"
try
set theList to name of items of alias volumes_ whose name is not in excluded_
on error
tell me to return display dialog "No disks available." buttons �
{"OK"} default button 1 with icon 1
end try
end tell
set theDisk to (choose from list theList with prompt "Please select a disk") as text
if theDisk = "false" then return
set excludedUsers to {"Shared"}
try
tell application "Finder" to set theUsers to name of (items of folder (theDisk & ":Users")) whose name is not in excludedUsers
on error
tell me to return display dialog "No home directories available" buttons �
{"OK"} default button 1 with icon 2
end try
set theHome to (choose from list theUsers with prompt "Please select a home directory")
set byteSize to size of (info for alias theHome)
set size_ to convertByteSize from byteSize
to convertByteSize from byteSize -- by Nigel Garvey
if byteSize is greater than or equal to 1.099511627776E+12 then -- Terabytes (2 ^ 40)
((byteSize / 1.099511627776E+12 div 0.01 / 100.0) as string) & " TB"
else if byteSize is greater than or equal to 1.073741824E+9 then -- Gigabytes (2 ^ 30)
((byteSize / 1.073741824E+9 div 0.01 / 100.0) as string) & " GB"
else if byteSize is greater than or equal to 1048576 then -- Megabytes (2 ^ 20)
((byteSize / 1048576 div 0.01 / 100.0) as string) & " MB"
else if byteSize is greater than or equal to 1024 then -- Kilobytes (2 ^ 10)
((byteSize div 1024) as string) & " K"
else
(byteSize as string) & " bytes"
end if
end convertByteSize
display dialog "The directory " & theHome & " is " & size_ & " do you wish to continue?"
set excluded_ to {"Network"}
set volumes_ to (path to startup disk as text) & "Volumes"
tell application "Finder"
try
set theList to name of items of alias volumes_ whose name is not in excluded_
on error
tell me to return display dialog "No disks available." buttons ¬
{"OK"} default button 1 with icon 1
end try
end tell
set theDisk to (choose from list theList with prompt "Please select a disk") as text
if theDisk = "false" then return
set excludedUsers to {"Shared"}
try
tell application "Finder" to set theUsers to name of (items of folder (theDisk & ":Users")) whose name is not in excludedUsers
on error
tell me to return display dialog "No home directories available" buttons ¬
{"OK"} default button 1 with icon 2
end try
set theHome to (choose from list theUsers with prompt "Please select a home directory")
set byteSize to size of (info for alias (theDisk & ":Users:" & theHome))
set size_ to convertByteSize from byteSize
set dd to (display dialog "The directory named '" & theHome & "' is " & size_ & ". Do you wish to continue?" buttons ¬
{"No", "Yes"} default button 2 with icon 1)
if button returned of dd is "No" then
display dialog "You chose not to proceed - the script will now terminate."
-- User doesn't want to continue
return -- exit script
else
display dialog "Stand by for duplication."
-- User wants to continue
-- Copy the folder
end if
to convertByteSize from byteSize -- by Nigel Garvey
if byteSize is greater than or equal to 1.099511627776E+12 then -- Terabytes (2 ^ 40)
((byteSize / 1.099511627776E+12 div 0.01 / 100.0) as string) & " TB"
else if byteSize is greater than or equal to 1.073741824E+9 then -- Gigabytes (2 ^ 30)
((byteSize / 1.073741824E+9 div 0.01 / 100.0) as string) & " GB"
else if byteSize is greater than or equal to 1048576 then -- Megabytes (2 ^ 20)
((byteSize / 1048576 div 0.01 / 100.0) as string) & " MB"
else if byteSize is greater than or equal to 1024 then -- Kilobytes (2 ^ 10)
((byteSize div 1024) as string) & " K"
else
(byteSize as string) & " bytes"
end if
end convertByteSize
No animals were har…errr…no functionality was sacrificed during the rearranging of this code.
Rob, once again you come through. Can you see where I am going with this script now?
My next step, is of course to copy the users folder to the loaner (my old scripts invoked shell commands so that I could give ownership as well, but now with all these variables, I need to figure out how to pass the results form an AppleScript into a shell script).
By the way, this script is run in the root account of the loaner. That way, the script queries the users on the other computer (mounted firewire), and copies over to the loaner (either a prenamed account or I might get into editing the NIDB within the script, for now I’m sticking with just replacing the 'student" home folder on the loaner).
Thanks again! It’s nice to have someone willing to lend a a hand. Hope you don’t go on vacation!!!
Note: I am not much of a shell scripter. The following example is provided only as an example of how you can use AppleScript variables in a shell script. The shell script will not be executed.
I find that it’s easier, at least during debugging, to build the command, save it in a variable and then pass it to the do shell script command.
set excluded_ to {"Network"}
set volumes_ to (path to startup disk as text) & "Volumes"
tell application "Finder"
try
set theList to name of items of alias volumes_ whose name is not in excluded_
on error
tell me to return display dialog "No disks available." buttons ¬
{"OK"} default button 1 with icon 1
end try
end tell
set theDisk to (choose from list theList with prompt "Please select a disk") as text
if theDisk = "false" then return
set excludedUsers to {"Shared"}
try
tell application "Finder" to set theUsers to name of (items of folder (theDisk & ":Users")) whose name is not in excludedUsers
on error
tell me to return display dialog "No home directories available" buttons ¬
{"OK"} default button 1 with icon 2
end try
set theHome to (choose from list theUsers with prompt "Please select a home directory") as text
set byteSize to size of (info for alias (theDisk & ":Users:" & theHome))
set size_ to convertByteSize from byteSize
set dd to (display dialog "The directory named '" & theHome & "' is " & size_ & ". Do you wish to continue?" buttons ¬
{"No", "Yes"} default button 2 with icon 1)
if button returned of dd is "No" then -- exit script
display dialog "You chose not to proceed - the script will now terminate."
return -- exit script
else -- proceed with duplication
display dialog "Stand by for duplication."
set source_ to quoted form of POSIX path of (theDisk & ":Users:" & theHome)
set target_ to quoted form of POSIX path of "path:to:student folder"
set shell_command to "ditto -rsrcFork " & source_ & " " & target_
--do shell script shell_command
end if
to convertByteSize from byteSize -- by Nigel Garvey
if byteSize is greater than or equal to 1.099511627776E+12 then -- Terabytes (2 ^ 40)
((byteSize / 1.099511627776E+12 div 0.01 / 100.0) as string) & " TB"
else if byteSize is greater than or equal to 1.073741824E+9 then -- Gigabytes (2 ^ 30)
((byteSize / 1.073741824E+9 div 0.01 / 100.0) as string) & " GB"
else if byteSize is greater than or equal to 1048576 then -- Megabytes (2 ^ 20)
((byteSize / 1048576 div 0.01 / 100.0) as string) & " MB"
else if byteSize is greater than or equal to 1024 then -- Kilobytes (2 ^ 10)
((byteSize div 1024) as string) & " K"
else
(byteSize as string) & " bytes"
end if
end convertByteSize
Maybe someone else will offer better shell code and advice regarding permissions.
Ahh, I see. I thought you would have to point to a shell script itself, didn’t know you could actually add the commands to the AppleScript itself. That’s helpful. I am going to go mess with this for a while. Thanks again.