0

私は AppleScript に不慣れで、問題を解決するのに役立つ適切な情報源が見つからないようです。日付と説明を含むファイルがあるとします。

  September 5, 2013
  Event 1.

  September 8, 2013
  Event 2.

  etc.

ファイルを解析して日付とイベント情報を取得し、Mac カレンダー アプリでこれらの日のイベントを作成します (これらの説明とイベント タイトルを使用)。ただし、次のコードで立ち往生しています。

tell application "Finder"
    set Names to paragraphs of (read (choose file with prompt "Pick text file containing track names"))
    repeat with nextLine in Names
        set x to "Thursday, " & nextLine & " 12:00:00 AM"
        if nextLine starts with "Sept" then
            tell application "Calendar"
                tell calendar "My Calendar"
                    make new event with properties {description:"Event Description", summary:"Event Name", location:"Event Location", start date:date x, allday event:true}
                end tell
            end tell
        end if
    end repeat
end tell

不適切な日付形式について不平を言うため、コードはまだ機能しません。さらに、日付行で 2 行目を読み取る方法がわかりません。助けていただければ幸いです、ありがとう。

4

1 に答える 1

2

外部ファイル形式を次のように変更することで、システムの日付解析の問題を解決しました。

5 September 2013

これは、Language & Text - System Preference で定義されているローカル システムの日付形式設定である可能性があります。おそらく最初に設定を調べてください。

ループをインデックス ベースのループに変更してイベント名を取得する方法を示すために、以下のスクリプトを少し修正しました。

また、Tell "Finder" ブロックは不要なので削除しました。この場合、Finder からコマンドを使用していませんでした。

また、いくつかの変数の名前をより読みやすく (主観的に) 変更しました。他の微調整はスクリプトにコメントされています。

set cal_data to the paragraphs of (read (choose file with prompt "Pick text file containing track names"))
set c to the count of cal_data

repeat with i from 1 to c
    set currentLine to item i of cal_data
    if currentLine contains "September" then
        set dt to date (currentLine) -- Dropped the time as an all day event does not need this and the date parse will auto set it to 12:00am
        set ev_name to item (i + 1) of cal_data -- The next item in cal_data  should be the event name      
        tell application "Calendar" 
            tell calendar "My Calendar"
                make new event with properties {description:"Event Description", summary:ev_name, location:"Event Location", start date:dt, allday event:true}
            end tell
        end tell
    end if

end repeat

うまくいけば、これで次のステップに進むことができます。

于 2013-09-06T07:57:27.247 に答える