Hi!
I’m trying to delete some files and I’m almost there…
But I just don’t want the Finder user/password dialog to pop up when I drag the files into the trash!
Does anyone have a solution …?
/Jonas
set modDate to (5)
tell application “System Events”
set currentUser to (name of current user)
end tell
tell application “Finder”
try
delete (every item of folder "_CCC Archives" of disk "Boot_copy" whose modification date is less than ((current date)) - modDate * days)
end try
do shell script "rm -rf ~/.Trash/*" user name "blablabla" password "blablabla" with administrator privileges
end tell
Hello.
I think there is only one way to do that and that is to grant adminstrator privileges to the account.
Either that, or write a c-program, so that you can change the owner of the program to root, and change the setuid bit, so it executes as root, for the user without administrative privileges.
IMHO, it may be slightly inconvenient, but absolutely safest to let the user enter the password.
Why ask the Finder to move files into the trash then delete the trash content ?
You may do the job in a single call :
apply the shell script to delete the files themselves from their original location.
Given the available infos, I’m not sure than a password would be required to do that.
If it’s not, it would be even easiest to ask System Events to do the job with such piece of code:
set sourceFolder to "Macintosh HD:Users:yvankoenig:Desktop:des chats copie:"
set textDateToCheck to "1/1/2013"
set dateToCheck to date textDateToCheck
tell application "System Events"
delete (every file of folder sourceFolder whose modification date is less than dateToCheck)
end tell
As you see, I didn’t use your own test about date because I tested upon an available folder whose files didn’t match your specs.
KOENIG Yvan (VALLAURIS, France) jeudi 30 mai 2013 19:10:51