Re: scripting secure empty trash (was: no subject)
Re: scripting secure empty trash (was: no subject)
- Subject: Re: scripting secure empty trash (was: no subject)
- From: kai <email@hidden>
- Date: Sat, 15 Jul 2006 20:00:13 +0100
On 15 Jul 2006, at 12:59, David Marshall wrote:
Just a note: if the user has "Show warning before emptying the
Trash" checked in Finder's "Advanced" prefs, they'll need to add a
"keystroke return" to the script.
- - - - -
tell application "Finder" to activate
tell application "System Events"
tell process "Finder"
click menu item 7 of menu "Finder" of ¬
menu bar item "Finder" of menu bar 1
keystroke return
end tell
end tell
- - - - -
Good point, Dave (I tend not to use the warning option).
A couple of minor issues arise from that here. If the keystroke
follows straight on from the menu click, the target button may not be
quite ready to register it (causing the warning dialog to stay put).
Also, if the warning option *isn't* checked in Finder's advanced
prefs, and a single item happens to be selected in Finder, the
keystroke selects the text of that item (which might, under certain
circumstances, lead to unexpected/undesirable results).
In Tiger, one or two additional checks could help to avoid these
possibilities:
----------------
tell application "Finder"
if (count trash's items) is 0 then return
activate
end tell
tell application "System Events"
set w to value of property list file ((path to preferences as
Unicode text) & ¬
"com.apple.finder.plist")'s property list item "WarnOnEmptyTrash"
tell application process "Finder"
click menu item 7 of menu "Finder" of menu bar item "Finder" of
menu bar 1
if w then tell button -1 of (first window whose subrole is
"AXDialog" and title is "")
repeat until exists
delay 0.1
end repeat
click
end tell
end tell
end tell
----------------
For more general use, I suppose something like this might do the trick:
----------------
tell application "Finder"
if (count trash's items) is 0 then return
activate
end tell
tell application "System Events" to tell process "Finder"
set c to count windows
click menu item 7 of menu "Finder" of menu bar item "Finder" of menu
bar 1
repeat 5 times
if (count windows) > c then
key code 36
exit repeat
end if
delay 0.1
end repeat
end tell
----------------
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden