Power Automate Desktop無償版のフローを無限ループで自動実行させる方法 

2025年2月9日

方法

1分ごとにチェックすることで毎日決まった時間やファイルの存在 5分ごとに動かすサンプルです

power automate desktop を常時起動しておく必要があります

コピペして使用してください

DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
SET NewVar TO $'''22:00'''
DateTime.Add DateTime: CurrentDateTime TimeToAdd: 5 TimeUnit: DateTime.TimeUnit.Minutes ResultedDate=> ScheduledDateTime
LOOP LoopIndex FROM 1 TO 11 STEP 0
    IF (File.IfFile.Exists File: $'''D:\\data2\\JIS.txt''') THEN
        Display.ShowMessageDialog.ShowMessageWithTimeout Title: ScheduledDateTime Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False Timeout: 3 ButtonPressed=> ButtonPressed
    END
    DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
    IF CurrentDateTime >= ScheduledDateTime THEN
        Display.ShowMessageDialog.ShowMessageWithTimeout Title: ScheduledDateTime Message: ScheduledDateTime Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False Timeout: 3 ButtonPressed=> ButtonPressed
        @@flowname: 'n'
External.RunFlow FlowId: '14c583cb-d750-41d3-bc01-c87a6e7d1244' WaitToComplete: True
        DateTime.Add DateTime: ScheduledDateTime TimeToAdd: 5 TimeUnit: DateTime.TimeUnit.Minutes ResultedDate=> ScheduledDateTime
    END
    Text.ConvertDateTimeToText.FromDateTime DateTime: CurrentDateTime StandardFormat: Text.WellKnownDateTimeFormat.ShortTime Result=> FormattedDateTime
    IF NewVar = FormattedDateTime THEN
        Display.ShowMessageDialog.ShowMessageWithTimeout Title: ScheduledDateTime Message: FormattedDateTime Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False Timeout: 3 ButtonPressed=> ButtonPressed
    END
    WAIT 60
END

説明

  1. 現在日時を取得:
    DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime => CurrentDateTime
    • 現在のローカル日時を取得し、変数 CurrentDateTime に保存します。
  2. 新しい変数を設定:
    SET NewVar TO $'''22:00'''
    • 文字列値 '22:00' を持つ新しい変数 NewVar を設定します。
  3. 現在日時に5分を追加:
    DateTime.Add DateTime: CurrentDateTime TimeToAdd: 5 TimeUnit: DateTime.TimeUnit.Minutes ResultedDate => ScheduledDateTime
    • 現在日時 (CurrentDateTime) に5分を追加し、その結果を ScheduledDateTime に保存します。
  4. ループ処理:
    LOOP LoopIndex FROM 1 TO 11 STEP 0
    • LoopIndex が1から11までの範囲で、ステップ0(つまり、ループの終了条件に達するまで無限に実行)でループを開始します。
  5. 特定のファイルの存在チェック:
    IF (File.IfFile.Exists File: $'''D:\\data2\\JIS.txt''') THEN Display.ShowMessageDialog.ShowMessageWithTimeout Title: ScheduledDateTime Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False Timeout: 3 ButtonPressed => ButtonPressed
    END
    • D:\\data2\\JIS.txt ファイルが存在するかどうかをチェックし、存在する場合は ScheduledDateTime をタイトルとするメッセージダイアログを表示します。このダイアログは3秒間表示されます。
  6. 現在日時の再取得:
    DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime => CurrentDateTime
    • ループの各反復で、現在のローカル日時を再取得します。
  7. スケジュールされた日時のチェック:
    IF CurrentDateTime >= ScheduledDateTime THEN
    Display.ShowMessageDialog.ShowMessageWithTimeout Title: ScheduledDateTime Message: ScheduledDateTime Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False Timeout: 3 ButtonPressed => ButtonPressed
    @@flowname: 'n' External.RunFlow FlowId: '14c583cb-d750-41d3-bc01-c87a6e7d1244' WaitToComplete: True DateTime.Add DateTime: ScheduledDateTime TimeToAdd: 5 TimeUnit: DateTime.TimeUnit.Minutes ResultedDate => ScheduledDateTime
    END
  8. 現在日時の短時間形式の文字列変換:
    Text.ConvertDateTimeToText.FromDateTime DateTime: CurrentDateTime StandardFormat: Text.WellKnownDateTimeFormat.ShortTime Result => FormattedDateTime
    • CurrentDateTime を短時間形式(例:’22:00’)の文字列に変換し、その結果を FormattedDateTime に保存します。
  9. 特定の時間のチェック:
    IF NewVar = FormattedDateTime THEN
    Display.ShowMessageDialog.ShowMessageWithTimeout Title: ScheduledDateTime Message: FormattedDateTime Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False Timeout: 3 ButtonPressed => ButtonPressed
    END
    • FormattedDateTimeNewVar と等しい場合、メッセージダイアログを表示します。
  10. ウェイト:
    WAIT 60
    • ループの各反復で60秒間待機します。

このプログラムは、一定の間隔で現在の時間をチェックし、特定の条件が満たされた場合にメッセージを表示。また、特定のフローを実行するトリガーとしても機能します。