I’m a newbie to AppleScript as well as to shell scipts and the Terminal. That said, I’ve decided to start learning by tackling a specific task I want to script, but I’ve gotten stuck right at the beginning of my script.
My goal is to write an AppleScript that’ll run at startup, check the modification dates of all the maintenance logs in /var/log to determine when they were last run and have the script decide whether they need to be run or not (if they weren’t run due to the Mac being off or whatnot).
My problem is trying to get the modification date of the daily, weekly, monthly log files. At first, I was getting a file not found error, which I thought had to do with the fact that they were invisible and owned by root. With the use of the POSIX on the file path, the file is now found, but I’m getting a Permissions Denied error despite, as you can see below, that I’m using with Adiminstrator privileges in the script.
In pouring over the forums on this site and some other web sites I managed to get this far:
set daily_log to do shell script (quoted form of POSIX path of "Macintosh HD:var:log:daily.out") ¬
user name "USER" password "PSWD" with administrator privileges
set daily_info to info for daily_log
set daily_last to modification date of daily_info
The remainder of the script will be the IF…THEN checks on the the modification dates with appropriate DO SHELL SCRIPT commands to run the maintenance scripts that need to be run. My logic in doing this? Basically, why run the scripts if they don’t need to be run? That is, if they ran on their own when they were suppose to.
Ultimately, I’m just not sure whether there’s a shell command to get specific info on a file/folder (like the mod date) that is owned by root (I searched but couldn’t find any info) or if I’m even placing the with administrator privileges in the right spot.
I’d really appreciate it if someone could guide me in getting this right and working. Also, if some generous AS guru could further guide me with the remainder of the script, particularly the date verifications I need to make, I would be even more appreciative.
Thanks.
Model: PM Dual 2GHz G5 (Tiger 10.4.2)
AppleScript: 1.1
Browser: Safari 412.2.2
Operating System: Mac OS X (10.4)