|
|
#1 |
|
Prospect
Join Date: May 2012
Location: TX, United States of America
Posts: 7
|
Applescript Empty trash then Logout
I've been trying to come up with an applescript to "secure empty" my trash then log me out. I eventually plan on having it work automatically at periodic times during the day, but I'm not worried about that right now. I used the "if" and "repeat" parts of it, because other wise I would just get a message saying it couldn't logout because the trash was still emptying.
--Trash tell application "System Events" to tell application process "Finder" set frontmost to true click menu item 7 of menu "Finder" of menu bar item "Finder" of menu bar 1 keystroke return end tell tell application "Finder" set Count_Trash_Items to count of items of trash if (Count_Trash_Items = 0) then display dialog "Logging out now" giving up after 2 else repeat until Count_Trash_Items is equal to 0 end repeat end if end tell --Log Out tell application "System Events" keystroke "Q" using {command down, option down, shift down} end tell It does secure empty the trash, but after that it just runs endlessly without giving a dialogue or logging me out. I would greatly appreciate any help in figuring out what is wrong with this. Thanks |
|
|
|
|
|
#2 |
|
Prospect
Join Date: Feb 2009
Location: Utrecht, NL
Posts: 8
|
It runs endlessly because Count_Trash_Items is not re-evaluated while repeating. This should work:
Code:
repeat until Count_Trash_Items is equal to 0
set Count_Trash_Items to count items of trash
delay 0.1
end repeat
|
|
|
|
|
|
#3 |
|
Major Leaguer
Join Date: Apr 2010
Posts: 330
|
Code:
tell app "finder"
empty trash security true
set count_trash_items to count of items of trash
repeat until (count (every file in trash)) = 0
delay 1.6 -- or however many seconds you want to it to loop
end repeat
end tell
tell app "system events" to log out keystroke "Q" using {command down, option down, shift down}
__________________
see a problem; solve a problem. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|