2016-09-20 5 views
0

AppleScriptを使って.txtファイルのテキストを解析し、別の.txtファイルに出力するための助けをいくつか使うことができます。 1)特定のセクションを特定する( "=")、2)特定の文字セットがセクションに存在するかどうかを特定するためのスクリプト、 "[*]"、3)セクションヘッダーを特定の文字セット、4)ファイルの最後まで繰り返します。基本的には、これらはアクションアイテムのあるノートです。オープンアクションアイテムを含むノートを抽出したいと思います。次のようにnotes.txtをからテキストをテキストで解析する

入力テキスト構造は、次のようにactionItems.txtへ

»=============================== 

<Date> 2016-09-19 
<Topic> The topic of the day 
<Attendees> Mario, Luigi 

»1) Where to go from here 
- Someone said this 
    [*] Mario: schedule this meeting 
- And who wants to do that other thing? 

»2) And on to the next thing 

»3) So on and so forth [*] Luigi can order the pizza 
»=============================== 

<Date> 2016-09-18 
<Topic> The topic of the yesterday 
<Attendees> Zelda, Wario, Snoop Dog 

»1) Where we went from there 
- Who said this 
    [x] Mario: scheduled this meeting yesterday 
- And who wants to do that other thing? 

»2) And on to the next thing again 

»3) So on and so forth * Luigi can order the sausages 
»=============================== 

テキストを出力するには、次のようになります。

»=============================== 

<Date> 2016-09-19 
<Topic> The topic of the day 
<Attendees> Mario, Luigi 

»1) Where to go from here 
- Someone said this 
    [*] Mario: schedule this meeting 
- And who wants to do that other thing? 

»3) So on and so forth [*] Luigi can order the pizza 
»=============================== 

たぶん私はこれで少しの助けを得ることができますか?ありがとう!

答えて

0

読書やテキストファイルを書くことのAppleScriptと非常に簡単です:

読む:ファイルにテキスト変数をnewTextの

set myFile to choose file "Select your txt file" -- ask user to select txt file 
set myText to (read myFile) as string -- content the text file is in variable myText 

書き込み内容デスクトップ上の 'アクションitems.txt':

set newFile to ((path to desktop) as string) & "actionItems.txt" 
try 
    open for access file newFile with write permission 
    write (newText & return) to file newFile starting at eof 
    close access file newFile 
on error 
try 
    close access file newFile 
end try 
end try 

間には、強力な「アイテムテキスト区切り文字」を使用してテキストを分割する必要があります。あなた最初のような区切り文字を定義する必要があります。あなたが次に(私のテスト中に、私はあなたの「»は、=」 『¬ª=』として設定し、実際に、あるべきことを発見!!)

set AppleScript's text item delimiters to {"»=", "¬ª="} 

をすることができます繰り返しループを介して各テキストアイテム(2つの区切り文字の間にテキストの一部)へのアクセス:

set AppleScript's text item delimiters to {"»=", "¬ª="} 
set myNotes to text items of myText 
set newText to "" 
repeat with I from 1 to (count of myNotes) --loop through each item 
    -- do what ever you need with 'item I of myNotes' 
    set Newtext to "this is my test" -- assign new text to be written 
end repeat 

あなたがループ内でテストを調整する必要があります:あなたのテキストがスペースで始まっている場合、たとえば、その後、第一アイテムはあなたの予想されるヘッダーではなく、スペースです!

最後の事:

Set A to "This is my text sample" 
if A contains "is my" then 
    -- A contains 'is my' 
else 
    -- A do not contains 'is my' 
end if 

幸運:テキスト変数が何かが含まれている場合、「含む」の単語を使用し、テストします!