I am somewhat of a beginner to AppleScript, I just have a question regarding writing to a file for security purposes. Basically, I wan’t to write to a file that the user doesn’t have direct access to so I can setup some sort of registration for the application (you can only use it a certain number of times until you have to register it). I know how to write to the prefs file, but that is easily accessible.
Thanks for the info, but I was more wondering if anybody knows how I would write IN the application itself. For example, if you were to use “show contents” on an application, you see what is contained inside, is there any way to save a file directly inside of there?
If you use “path to me”, it will point to your app:
--> update launch count
set f to ((path to me as text) & "Contents:MacOS:._invisiblefile") --> adjust the location here
set fRef to (open for access file f with write permission)
try --> read previous value
set oldContents to read fRef
set oldContents to (oldContents as number) + 1
on error
set oldContents to 1
end try
set eof of fRef to 0 --> empty file
write (oldContents as text) to fRef
close access fRef
--> run or not
if oldContents is 3 then
display dialog "demo expired!"
return
else
display dialog "" & (3 - oldContents) & " launches left!"
end if
--> continue
However, if you save the file inside your bundle, the demo will be re-activated when the user trashes the expired copy and installs a fresh copy
The best method I know is using a serial number validator. The app will limit its funcionalities unless you provide a serial number.