2017-08-28 7 views
0

私はそこに作成された新しいファイルに対して、AutoHotKeyがディスク上のフォルダを聞く/見ているようにしたいと思っています(c:\フォルダとしましょう)。AutoHotKeyを使用してフォルダ内に作成された新しいファイルを処理する方法は?

Send {Esc} Sleep, 100 Send {F5} Sleep, 100 Send {Home} Sleep, 100 Send s Sleep, 100 Send {Enter} Return

、それはように新しい変化とのフォルダを見に戻るべき後:新しいファイル・ショーのアップした場合、スクリプトは、一連のコマンドを実行する必要があります。私はそれがWatchDirectory()関数を使うべきであることを認識していますが、それを実装する方法はわかりません。どんな助け?どうも!

答えて

1

あなたはそれがあなたのスクリプトと同じ場所に置いてダウンロードし、あなたが行うことができ、WatchFolder()機能を使用することができます。あなたの答えのための

#Include %A_ScriptDir%\WatchFolder.ahk 

WatchFolder("c:\folder", "myFunc", , Watch := 1) 
return 

myFunc(path, changes) { 
    for k, change in changes 
     ; 1 means new file was added 
     if (change.action = 1) { 
      gosub doStuff 
      return 
     } 
} 

doStuff: 
; commands you want to execute 
return 
0

感謝を。私はあなたのコードを追加し、それは動作したくない、スクリプトがロードされていないようです(タスクバーのアイコンなし)。最終的なコードは次のようになります。

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 
; #Warn ; Enable warnings to assist with detecting common errors. 
SendMode Input ; Recommended for new scripts due to its superior speed and reliability. 
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. 


#Include %A_ScriptDir%\WatchFolder.ahk 

WatchFolder("C:\Users\kris\Desktop\temp", "myFunc", , Watch := 1) 
return 

myFunc(path, changes) { 
for k, change in changes 
    ; 1 means new file was added 
    if (change.action = 1) { 
     gosub doStuff 
     return 
    } 
} 

doStuff: 
    Send {Esc} 
    Sleep, 500 
    Send {F5} 
    Sleep, 100 
    Send {Home} 
    Sleep, 100 
    Send s 
    Sleep, 100 
    Send {Enter} 
return 

スクリプトと同じフォルダにWatchFolder.ahkを挿入しました。

+0

これは、ホットキーがなく、ただ終了するためです。最初に '#Persistent'を追加すれば、それは動いていきます。 – Oleg

+0

Thx!魅力的な作品:) –

関連する問題