NEWBIE - Setting mod date of an invisible root log file

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.


Model: PM Dual 2GHz G5 (Tiger 10.4.2)
AppleScript: 1.1
Browser: Safari 412.2.2
Operating System: Mac OS X (10.4)

Hi glazaros,

This seems to work fo me (perhaps you need to be Admin on the computer for this to work?):

set daily_log to "Macintosh HD:var:log:daily.out"
set daily_last to modification date of (info for file daily_log)

And to compare the dates would be:

(current date) - daily_last

So something like:

set daily_log to "Macintosh HD:var:log:daily.out"
set daily_last to modification date of (info for file daily_log)
if (current date) - daily_last is greater than 1 * days then
	-- do stuff here
end if

Would seem to me to be basically what you are asking for.

Best wishes

John M

The Finder should see invisibles. Try this:

tell application "Finder" to set LogFiles to files of alias ""Macintosh HD:var:log:"
repeat with ThisFile in LogFiles
	tell application "Finder" to set MODdate to modification date of ThisFile
	display dialog (name of ThisFile) & return & "Mod Date: " & MODdate --Take this out, here for your testing
	if MODdate is not (current date) then --Example condition
		do shell script ""
	end if
end repeat


John M…Thanks a lot. Your 2 lines for getting the mod date worked right off the bat.

You know, I had the daily_log variable set to the log file exactly the way you just laid it out when I first started, but it didn’t work and I had administrator privileges on my user account as well. I’m not sure what happened, but I think that maybe my original syntax for getting the file info was wrong and I was misunderstanding the error message and in subsequent iterations to try to get it to work I over-complicated it and it broke.

For instance, I know that my line for setting the mod date didn’t put info for file daily_log in parentheses like you did and wasn’t working. I’ve noticed that AS is flexible enough that one could write out the same code line a few different ways and will work. So, this might be a real newbie question, but how do you know when to put something in parentheses in regard to AS syntax?

Also, thanks for the date IF…THEN statement. I haven’t tried it yet, but it should help me in easily finishing this script.


sitcom thanks for your input. I think I know what your script is aiming to do and it gives me an idea for something else I’d like to try.

I’m figuring that your script will look at all the contents of the log folder and get/display their mod dates and then act on those mod dates (if they’re off) with a do shell script command. Right?

However, even after removing the extra quote mark at the beginning of the directory path in your script, I still get a “file not found” error. What does “files of alias” exactly do? Not knowing much, it seems it looks for alias files, but I’m not sure. I did look in the disctionary for this and didn’t find a clear answer.



It’s not a newbie question, for me it’s trial & error as to when it’s needed. Usually when you can put something on two lines instead of one it’s probably good practice to add the parentheses, so you can see what’s happening as much as anything else.

Best wishes

John M

You’re absolutely right John M.

Right before I got your last posting I was working on a display dialog command which AS was returning an error on. I read your posting and threw parentheses on the content portion of the command and it worked. It is pretty arbitrary, that’s for sure.

I think I’m getting the hang of this little by little.

Thanks again,