2
votes

I am new to AutoHotKey usage. I am using Version 1 syntax.

I want to watch a text file for any changes/modifications and if the text file is modified then I want to copy the contents of the Text file to clipboard.

When I run the below script then I don't see any errors but the clipboard is not working. What am I doing wrong here?

#SingleInstance
#Persistent

global ClipboardFile := "C:\\Users\\Username\\OneDrive - Folder\\clipboard.txt"
global Timestamp
FileGetTime, Timestamp, ClipboardFile, M
SetTimer , isFileModified, 1000
return

isFileModified() {
  FileGetTime, TimestampModified, ClipboardFile, M

  if ( Timestamp < TimestampModified ) {
    global Timestamp := TimestampModified

    FileRead, ClipboardText, ClipboardFile
    ClipboardText := StrReplace(ClipboardText, "`n", "`r`n")
    clipboard := ClipboardText

    TrayTip , "Clipboard is updated successfully"
  }

}
1

1 Answers

1
votes
myFile := "C:\Users\user\myFileName.txt"
SetTimer, isFileModified, 1000
Return
isFileModified() 
{
    Global
    ToolTip
    FileGetTime, myNewTime, % myFile
    If(myOldTime = "")
        myOldTime := myNewTime, Return
    If(myOldTime = myNewTime)
        Return
    myOldTime := myNewTime
    SoundBeep, 444, 999
    MsgBox % "Modified.."
}