Replacing records in "Numbers" table
Post ReplyReplacing records in "Numbers" tablePosted: Friday, August 27, 2010 [20:58:07] - 1
I have a need to update records from plain text file on a daily basis. Honestly, got tired of it, and decided to make a small applescript that'll do it automatically. I saved the script as an application and dropped it on a dock. Now all I have to do is get a text file in-place and click on an app. Here is an applescript: -- adjust path to your Numbers file accordingly set p to "/current.numbers" set a to POSIX file p -- open Numbers file - calling a subroutine doOpenDocument(a) -- a little of embedded Perl script that'll read the plain text file - /current.txt -- adjust path to your text file accordingly set bList to do shell script "perl -e '$d = `cat /current.txt`;@w=split(/\\n/,$d);foreach $l(@w){if($l =~ m/\\bABA\\b/){next;}print\"$b$l\";$b=\";;\";}'" -- create an array. each element equals one line in a text file set myArray to splitData(";;", bList) -- now getting a number of lines in text file (records separated by Tab and it includes the Header row -- so Perl cuts the header row out and returns clean number of lines set nOfLines to do shell script "perl -e '$d = `cat /current.txt`;$d=~ s/\\n+$//;$nof = $d =~ s/\\n/$&/g;print\"$nof\";'" if nOfLines > 0 then end if on doOpenDocument(theDocument) end doOpenDocument on splitData(delimeter, splText) end splitData That is it |