Go Back   The macosxhints Forums > OS X Help Requests > AppleScript



Reply
 
Thread Tools Rate Thread Display Modes
Old 05-19-2012, 11:52 AM   #1
mitchmac24
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
mitchmac24 is offline   Reply With Quote
Old 05-31-2012, 02:44 PM   #2
alastor933
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
The delay keeps the # of repeats at a digestible level.
alastor933 is offline   Reply With Quote
Old 07-07-2012, 07:13 PM   #3
sojourner
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.
sojourner is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 11:39 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.