I need to remove all but one file from a folder on multiple machines. I have the Applescript and it works in an admin account, but needs authentication in user level accounts. Is there either a Unix command that will do the same thing or a way to set the contents of the folder as a variable and then use a Unix command to remove those? Help would be greatly appreciated. At the moment, my script looks like this:
tell application "Finder"
try
set apps_ to path to "apps"
set legalFolder to "Adobe Illustrator CS2:Legal"
set fullFolder to apps_ & legalFolder as text
delete (every item of folder fullFolder whose name is not "International English.html")
end try
end tell
tell application "Finder"
try
set apps_ to path to "apps"
set legalFolder to "Adobe Photoshop CS2:Legal"
set fullFolder to apps_ & legalFolder as text
delete (every item of folder fullFolder whose name is not "International English.html")
end try
end tell
I have another version that incorporates an authentication script I used for System Preference scripting - but I’ve never been able to get it to work outside of System Preferences. Perhaps I’m doing something wrong. The basis of the code is below:
to authenticate_changes()
tell application "System Events"
tell window "Authenticate" of process "SecurityAgent"
tell group 1
set value of text field 1 to adminText
set value of text field 2 to pass
end tell
click button "OK" of group 2
end tell
end tell
end authenticate_changes
When incorporating, I tried using the “my authenticate_changes” command within the try block- but it’s never worked.
Suggestions?