Hi,
I’m new here and a total beginner in applescript. I searched several threads, but could not really advance with my problem…
I’d like to know if it’s possible to do the following thing with an Applescript:
- Start application CCleaner for Mac (by Piriform.com) (*** important remark: see below!!! ***)
- Start CCleaner’s cleaning process
- When the Cleaning process is done, quit CCleaner
I’ve been able to make a script for the first two steps - here’s my code for that:
tell application "CCleaner"
activate
tell application "System Events"
click button "Run Cleaner" of window "Ccleaner" of process "CCleaner"
end tell
end tell
So, this starts up CCleaner and presses all the buttons/menus necessary to do the cleaning.
It’s step 3 I’m having problems with. How do I get the script to determine the cleaning process itself is over? I thought about something with an idle handler, something like the following code, but I can’t seem to get it to work:
global quit_after, check_every
set quit_after to 6
set check_every to 2
display dialog "Check is performed every " & check_every & " seconds. Things will be quit after " & quit_after & " seconds of system inactivity."
on reopen
display dialog "Check is performed every " & check_every & " seconds. Things will be quit after " & quit_after & " seconds of system inactivity."
end reopen
on idle
set idletime to do shell script "echo $((`ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000))"
if (idletime as integer) > quit_after then
tell application "System Events"
if ((name of processes) contains "CCleaner") then
tell application "CCleaner" to quit
quit me
end if
end tell
end if
return check_every
end idle
It works perfectly if I just Analyze my Mac with CCleaner (there are two buttons: Analyze and Run Cleaner: see the first screenshot on the link: http://www.piriform.com/mac/ccleaner), but it doesn’t work when I Run cleaner (in the first part of my script, by making the script press that button): there’s more time needed. The thing is: the amount of time needed isn’t a constant, I want the script to wait until the cleaning process is done without having to use a long delay…
Any help would welcome! Thanks in advance!
Joe D.
*** important remark ***
ABOUT CCLEANER: I don’t want to start a discussion about cleaning “your Mac” or about using third party apps to do it - I just want a solution for my problem. So, please, see it as a challenge in Applescript, and not as the 1000th discussion whether one should or should not clean his Mac… THANKS!
Model: iMac
AppleScript: 2.3
Browser: Firefox 12.0
Operating System: Mac OS X (10.6)