sarah
sarah

Reputation: 21

applescript: empty trash without warning

I am currently trying to write an applescript to empty the trash without displaying the warning.

I used "empty trash" it works fine if it was running as script, but if I save it as application it displays the warning "Are you sure you want to permanently erase the items in the Trash?".

so I am not sure what to add in order to disable the warning from appearing when running as an application.

I am using mac OS X 10.10.5

thank you

Upvotes: 2

Views: 4555

Answers (4)

Jason Magnuson
Jason Magnuson

Reputation: 1

On idle 
tell application "Finder"
   set my count to count of items of the trash
   If my count > 1 then
     set warns before emptying of trash to false
     empty trash
   End if
end tell
 Return 60 
End idle

Upvotes: 0

CJK
CJK

Reputation: 6092

Offering an alternative just for joy of having it out there:

do shell script "rm -R ~/.Trash"

for local trash, with the additional emptying of iCloud trashed files using:

do shell script "rm -R ~/Library/Mobile\ Documents/com~apple~CloudDocs/.Trash"

Sadly, there’s no sound effect with these.

NB. These we’re tested on MacOS 10.13. The first command will work on earlier systems. The second will depend on how your system integrates with iCloud, but hold more relevance for Sierra and High Sierra users that opt to have Desktop and Documents folders stored in iCloud.

Upvotes: 0

JWWalker
JWWalker

Reputation: 22707

The warning is a preference, but you can turn it off.

tell application "Finder"
    set warns before emptying of trash to false
    empty trash
end tell

Of course, if you want to be nicer, you could save the setting and restore it at the end.

Upvotes: 3

user3439894
user3439894

Reputation: 7555

The following works for me without any prompt:

tell application "Finder" to empty trash

Upvotes: 2

Related Questions