Modification date based script

I want to remind users to return their MacBook Pros at six month intervals. I composed this script, will place on their macs and will use crontab to run it.

tell application “Finder”

set the source_file to "MacName/Library/Logs/Software Update.log"

if source_file(modification date) is greater than "180 days" then
	
	display dialog "Please return this MacBook Pro for required maintenance."
	
end if

end tell

When I run the script I get the following message: “Finder got an error: Can’t continue source_file.”

So I tried a different approach:

tell application “Finder”

set modDate to the modification date of item "MacName2.2/Library/Logs/Software Update.log"

if modDate is greater than "180 days" then

	display dialog "Please return this MacBook Pro for required maintenance."
	
end if

end tell

and got this error: Finder got an error: Can’t get item “MacMini/Library/Logs/Software Update.log”.

Any suggestions would be greatly appreciated.

thanks…

Model: Mac Mini 166 Core Duo
AppleScript: 2.2
Browser: Firefox 2.0.0.16
Operating System: Mac OS X (10.5)

Hi,

the first script uses a handler call source_file(modification date) which needs the prefix my to work properly in a application tell block.

tell application "Finder"
	set the source_file to "MacName/Library/Logs/Software Update.log"
	if my source_file(modification date) is greater than "180 days" then
		display dialog "Please return this MacBook Pro for required maintenance."
	end if
end tell

But the script won’t run anyway without the handler.

The second script specifies the file with a POSIX path (slash separated).
AppleScript works only with HFS paths (colon separated)


tell application "Finder"
	set modDate to the modification date of file "MacName2.2:Library:Logs:Software Update.log"
	if modDate is greater than "180 days" then
		display dialog "Please return this MacBook Pro for required maintenance."
	end if
end tell

But this script won’t work either, because you can’t compare a date (modification date) with a literal string (“180 days”)
A date can only be compared with a date.
You probably mean


.
if modDate is less than (current date) - 180 * days then
.

Thanks for your quick response. I modified my script with your suggestion and it compiles fine. When I run the script I get this error:

Can’t get modification date of “PC2868_A:Library:Logs:Software Update.log”.

New script with modification:

tell application “Finder”

set the source_file to "PC2868_A:Library:Logs:Software Update.log"

set modDate to the modification date of source_file

if modDate is less than (current date) - 180 * days then
	
	display dialog "Please return this MacBook Pro for required maintenance."
	
end if

end tell

Thanks again…

the modification of your script wasn’t complete :wink:

set the source_file to file "PC2868_A:Library:Logs:Software Update.log

btw: you can refer to the log file regardless of the name of the startup volume

set the source_file to file ((path to library folder as text) & "Logs:Software Update.log")

Thank you for your help. My (your)script is working perfectly. Now I can harass users until they submit and surrender their MacBooks without any effort.

polard12