Right now I have a script that writes the current date to a file. When the app opens, it reads that file to see how old the date in the file is. If the date was past 15 days ago, the demo period is over and the app quits. I have however run into one problem with my script.
try
set firstUsed to (read file ((path to preferences as Unicode text) & "Example.dat") from 1 as date)
set Purchase to display dialog "You are currently using a demo version of this application, would you like to purchase a license?" buttons {"Yes", "No"} default button 1
if button returned of Purchase is "Yes" then
tell application "Safari"
make new document with properties {URL:"http://www.google.com"}
end tell
else if button returned of Purchase is "No" then
-- do nothing
end if
on error
set userPrefs to (path to preferences as Unicode text)
set F to (userPrefs & "Example.dat")
set _Date to (current date) as date
set fRef to open for access file F with write permission
try
set eof fRef to 0
write _Date as date to fRef
end try
close access fRef
set firstUsed to (read file ((path to preferences as Unicode text) & "Example.dat") from 1 as date)
end try
set currentDate to (current date)
display dialog currentDate as string
display dialog firstUsed as string
if ((currentDate - 15) > firstUsed) then
display dialog "I will quit now!"
else
display dialog "Hey!"
end if
The display dialog shows that firstUsed is January in 1904, not the date that is actually in the file. I can’t seem to get past this and have tried tons. Any help?