How to save a number variable to file in applescript? -


i trying make simple counter adds 1 count every time script run. have tried using property doesn't work because resets whenever script edited or computer turned off. here code have took here.

    set thefile ":users:hardware:library:scripts:applications:lightspeed:" & "currentproductcode.txt"  open access thefile set filecontents read thefile close access thefile  set counter filecontents integer  on add_leading_zeros(counter, max_leading_zeros)     set threshold_number (10 ^ max_leading_zeros) integer     if counter less threshold_number         set leading_zeros ""         set digit_count length of ((counter div 1) string)         set character_count (max_leading_zeros + 1) - digit_count         repeat character_count times             set leading_zeros (the leading_zeros & "0") string         end repeat         return (leading_zeros & (counter text)) string     else         return counter text     end if end add_leading_zeros  add_leading_zeros(counter, 6)   open access newfile write permission set eof of newfile 0 write counter + 1 newfile close access newfile 

with error:

can’t make ":users:hardware:library:scripts:applications:lightspeed:currentproductcode.txt" type file.

if add "set thefile thefile alias" after first "open access thefile" gets little further in code, gets error:

can’t make "1776" type integer.

and out of ideas. have googled on place haven't found works me. thanks

i use script objects store data:

set thepath (path desktop text) & "mydata.scpt"  script thedata     property counter : missing value end script  try     set thedata load script file thepath on error     -- on first run, set initial value of variable     set thedata's counter 0 end try  --increment variable 1 set thedata's counter (thedata's counter) + 1  -- save changes store script thedata in file thepath replacing yes return thedata's counter 

Comments