Newbie seeks solution for computer maintenace tasks

Howdy all,

I am brand new to apple scripting. I started looking for a way to perform the normally scheduled maintenance tasks for my iMac G5, and I encountered Apple Scripting. Looks very interesting to me.

I don’t like the idea of leaving my computer on all night, so the background maintenance tasks involving those log and temporary files, never get done. There is a way to manually initiate those tasks . . . but they require opening the Terminal application, typing a command (for daily, weekly or monthly procedures), then entering an administrator’s password.

I was thinking it would be nice if I could automate this process, and choose from three or four buttons (cancel, daily, weekly or monthly) and have this process perform automatically, without opening the Terminal program and typing in those commands.

But it seems it would be necessary to enter a password at some point. Do you folks know if it is possible to use a routine that will automatically enter a password when it is required? And if so, what is the “keyword”? Or can a simple variable be used?

Is what I am trying to do, feasible at all?

I am relatively new to the Mac, but I have spent about 15 years on PCs. And I used to program extensively with the Batch language, on PCs. This Applescript looks like it is FAR superior to the DOS Batch programming language.

I look forward to reading any tips or advice, specific or general, that you might care to talk about.

Thanks for your time.

Big Brad

It is completely feasible.

Those maintenance scripts are:

Shell commands are performed by using:

Or if you need a password (will prompt):

So try this:

-- show a list of choices and store the result(s) in the_choice
set the_choice to choose from list {"Daily", "Weekly", "Monthly"} with prompt "Maintenance scripts:" with multiple selections allowed
-- if the user presses the "Cancel" button it returns false
if the_choice is not false then
	-- perform appropriate tasks for each choice
	-- the_choice would be something like {"Daily","Monthly"} depending upon what the user has chosen
	if the_choice contains "Daily" then do shell script "sh /etc/periodic/daily/500.daily" with administrator privileges
	if the_choice contains "Weekly" then do shell script "sh /etc/periodic/weekly/500.weekly" with administrator privileges
	if the_choice contains "Monthly" then do shell script "sh /etc/periodic/monthly/500.monthly" with administrator privileges
	-- Tell the user that all the tasks were successful
	display dialog "Maintenance complete." buttons "OK" default button 1 giving up after 10
end if

Qwerty Denzel,

Wow! That’s so much more than I expected!

I have yet to write my first Apple Script, and now I have a “real world” example to use as the basis for further study. You have helped GREATLY!

Thanks a million,

Big Brad

P.S. I just ran this script and BOY! . . . was it elegant! Much better than I had originally imagined. Now I can see what CAN be done. Thanks again!

Model: iMac G5
AppleScript: 1.10
Browser: Safari 412.2
Operating System: Mac OS X (10.4)

Glad to help!

And welcome! :slight_smile: