The script below, obviously, gives me a list of all the items in the Users folder.
What I need it to exclude everything except for actual users. This means excluding “Shared”, “.DS_Store”, and “.localized”. Any idea how I can use an “excludedItems” property in my script so that it does not show these items?
Many thanks for any help.
tell application "Finder"
list folder "Macintosh HD:Users"
set theList to result
set theChoices to (choose from list theList)
end tell
set excluded_ to {"Shared"}
tell application "Finder" to ¬
set theList to name of items of (path to "usrs") whose name is not in excluded_
set theChoices to (choose from list theList)
I also need to do the same thing with mounted volumes, but changing path to “usrs” to path to “volumes” does not work. Any ideas?
set excluded_ to {"Network"}
tell application "Finder" to set theList to name of items of (path to "volumes") whose name is not in excluded_
set theChoices to (choose from list theList with prompt "Please select a disk")
set excluded_ to {"Network"}
set volumes_ to (path to startup disk as text) & "Volumes"
tell application "Finder"
set theList to name of items of alias volumes_ whose name is not in excluded_
end tell
set theChoices to (choose from list theList with prompt "Please select a disk")
“path to” takes one of a set of predefined 4-character enumerators, like “usrs”. You could also use “user folder” without the quotes. I don’t know of an enumerator or constant for the “Volumes” folder. Have you tried the “list disks” command? Or, you could use:
tell application “Finder” to set theList to name of items of folder (((startup disk) as string) & “Volumes:”)
OR
set theList to list disks
The latter will also include “Network”; you can put that in your excludes. Note that both will include any mounted disk images or removable media.
If you choose not to use one of Allen’s suggestions, maybe this will work. The error appears to be caused when no disks/volumes are available (after exclusions).
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 theChoices to (choose from list theList with prompt "Please select a disk")
Allen and Rob, this is great. I appreciate your help. Here’s some more for ya, if you are feeling up to it:
Once I get the disk selected, I want to be able to list the contents of the Users folder on that selected disk. The stuff Rob sent is great, the disk is selected OK. Here’s my broken code (using most of Rob’s stuff
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 theChoices to (choose from list theList with prompt "Please select a disk")
set theDisk to result
if theDisk = false then return
set excludedUsers to {"Shared"}
tell application "Finder" to set theUsers to name of items of theDisk & ":Users" whose name is not in excludedUsers_
set theHome to (choose from list theList with prompt "Please select a home directory")
It looks like this is the damaged command:
tell application “Finder” to set theUsers to name of items of theDisk & “:Users” whose name is not in excludedUsers_
the result is: Can’t get name of {“Macintosh HD”}.
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 user folders available." buttons ¬
{"OK"} default button 1 with icon 1
end try
set theHome to (choose from list theUsers with prompt "Please select a home directory") as text
Rob, you really are the shiznit. That works swell.
I’ve tried all kinds of stuff, and you just say “maybe this will work”, and of course it does.
Sort of unrelated, but how difficult is it to implement these types of scripts into AppleScript studio. I just got a a few books on this stuff, and I’m wondering if it’s pretty simple or am I going to “regret it”.
I’m glad the script works. FYI, it appears that you can safely remove “if theDisk = false then return”. Regarding AppleScript Studio, I can’t offer much because I haven’t taken the plunge.