image
image

Go Back   macosx.com > Mac Help Forums > HOWTO & FAQs

Reply
 
Thread Tools
  #1  
Old December 17th, 2003, 08:53 PM
Urbansory's Avatar
The Definition of...
 
Join Date: Apr 2002
Location: Atlanta, GA
Posts: 1,180
Thanks: 0
Thanked 0 Times in 0 Posts
Urbansory is on a distinguished road
[How To] Applescript the command line

I created routine maintenance Applescript out of curiosity and the need for a free solution that I could setup to run my daily/weekly and monthly.

Preparation--
I have mine setup to run from Entourage X, but i believe you can use iCal to run them on a timed schedule, or simply run them as applications when you see fit or from within Script Editor, where you can use the Result window to show the script processing *More on this later.
Setting up a new Key in Keychain------
The Settings I used are as follows:

Name: applescriptAllow
Kind: application password
Account: *Your User account
Where: applescriptallow
Password: Your user account password/ *Administrator password
The Script------
property theAppName : "weekly run script"
property myKeyName : "applescriptAllow" --Name of the key in Keychain Access

-------------------------Other global properties-----------------------------
property fromRun : false --whether we have entered the main run loop yet (true) or not (false)


on theCommands(thePassword)

--This runs the actual script using your Administrator password
--Substitute "weekly" for "daily" or monthly" to run those scripts

do shell script "sudo /etc/weekly" password thePassword with administrator privileges


do shell script "sudo -k" --timeout our sudo ability for security

end theCommands


(*
* Main handler.
*)
on run


set {thekey} to getKey()



tell application "Keychain Scripting" to set thePassword to password of thekey

theCommands(thePassword)

--reinitialize fromRun for the next time the script is run.

end run


on getKey()
set validKey to false
set changedPassword to false

tell application "Keychain Scripting"
set theKeychain to current keychain

tell theKeychain


set thekey to every generic key of theKeychain whose name is myKeyName
if thekey = {} then
set thekey to my makeKey()
set firstTime to true
set validKey to true
else
set thekey to item 1 of thekey
set firstTime to false
end if

end tell --end tell theKeychain

end tell --end tell application Keychain Scripting

repeat while not validKey
tell application "Keychain Scripting" to set thePassword to the password of thekey

try
do shell script "sudo -k" --timeout our sudo ability so the following test is valid
do shell script "ls /private/var/root/" password thePassword with administrator privileges
do shell script "sudo -k" --timeout our sudo ability for security
set validKey to true

on error
set thePassword to text returned of ¬
(display dialog "The Administrator password stored by “" & theAppName & "” is no longer valid. Please enter your valid Administrator password.

NOTE: the password will be displayed in plain text, but will be securly stored in your keychain." default answer "" with icon caution)

set changedPassword to true
set validKey to false

end try
end repeat

if changedPassword then tell application "Keychain Scripting" to ¬
set the password of thekey to thePassword

return {thekey}
end getKey
The Script End------

How to setup this script with Entourage X coming soon.

Initial script post 12-17-03
__________________
L. Jones
www.urbansory.com

Mac Pro 2.66 ghz - 3 Gig RAM - 10.4.10
G4 400 mhz - 960MB RAM - 10.4.7 & 9.2.1 (Seperate partitions)
Work: Mac Pro 2.66 ghz - 4 Gig RAM - 10.4.-
Reply With Quote
  #2  
Old June 23rd, 2005, 05:39 PM
Urbansory's Avatar
The Definition of...
 
Join Date: Apr 2002
Location: Atlanta, GA
Posts: 1,180
Thanks: 0
Thanked 0 Times in 0 Posts
Urbansory is on a distinguished road
Credit where credit is due...

Some of this code is from anice lil script...
http://www.oakandapple.plus.com/soft...legedExec.html

By..
Oak & Apple Productions
__________________
L. Jones
www.urbansory.com

Mac Pro 2.66 ghz - 3 Gig RAM - 10.4.10
G4 400 mhz - 960MB RAM - 10.4.7 & 9.2.1 (Seperate partitions)
Work: Mac Pro 2.66 ghz - 4 Gig RAM - 10.4.-
Reply With Quote
Reply

Thread Tools

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 07:06 AM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.