Jump to content

Write to txt file


olo
 Share

Recommended Posts

Hi Folks,

I have the clipboard output data and the message box displays it. However I cannot seem to copy the clipboard contents to a txt file.

Can anyone help?

ClipPut($sContent1 & @CRLF & $sContent2 & @CRLF & $sContent3 & @CRLF & $sContent4 & @CRLF & $sContent5 & @CRLF & $sContent6)

MsgBox(0,"Please Work", ClipGet(),4)

Local $OLO = FileOpen("PCData.csv", 1)
FileWrite($OLO, ClipGet())
FileClose($OLO)
Link to comment
Share on other sites

Works for me. What is $content1?

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

What is the exact problem? Is the file empty, or is there no file at all?

As mentioned above, the script (without the first line) works for me.

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Try to use an absolute path, as right now you're relying on the working directory e.g.

@ScriptDir & '\SomeFile.txt'

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • Moderators

Does this:

MsgBox(0, "", $sContent1 & @CRLF & $sContent2 & @CRLF & $sContent3 & @CRLF & $sContent4 & @CRLF & $sContent5 & @CRLF & $sContent6)

return what you expect?

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Also you're using 1 which means append to the end of an existing file. Try this >>

ClipPut($sContent1 & @CRLF & $sContent2 & @CRLF & $sContent3 & @CRLF & $sContent4 & @CRLF & $sContent5 & @CRLF & $sContent6)

MsgBox(0,"Please Work", ClipGet(),4)

Local $OLO = FileOpen(@ScriptDir & "\PCData.csv", 2)
FileWrite($OLO, ClipGet())
FileClose($OLO)

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Also you're using 1 which means append to the end of an existing file. Try this >>

ClipPut($sContent1 & @CRLF & $sContent2 & @CRLF & $sContent3 & @CRLF & $sContent4 & @CRLF & $sContent5 & @CRLF & $sContent6)

MsgBox(0,"Please Work", ClipGet(),4)

Local $OLO = FileOpen(@ScriptDir & "\PCData.csv", 2)
FileWrite($OLO, ClipGet())
FileClose($OLO)

Didnt seem to work :(
Link to comment
Share on other sites

This works for me, sorry.

#include <Constants.au3>

Local $hFileOpen = FileOpen(@ScriptDir & '\SomeFile.txt', $FO_OVERWRITE)
FileWrite($hFileOpen, 'Some__Data' & @CRLF)
FileClose($hFileOpen)

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Didnt seem to work :(

What do you mean by "didn't seem to work"? What are the return values of the functions you call? What's the value of @error after you called a function?

Please be more specific!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

ok here is my full code.

Now the idea of the program is simple.

  • Basically open a pdf and navigate to a section called power consumption.
  • The power consumption is split into 6 rows and 5 columns.
  • Now I want to copy 1 row at a time and store it in a variable. So $row1 , $row2 etc
  • Then once done for the 6 rows, copy the data stored in the 6 row variables to the clipboard
  • Then from the clipboard to a txt file.
A problem Im also having is that I use absolute positioning of the mouse. So I have to place the mouse at the starting value of each row.

N.B. Of course because its a PDF if there is a blank row(i.e. no data) it drags the pdf and puts off the other values of the other rows since they use specific mouse positioning.

please help ive been at this for a week now :

#include <String.au3>
#include <File.au3>
#include <Array.au3>
#include <Clipboard.au3>

;DECLARIATIONS

Local $PDFFileName = 'c:\acra\datasheet\adc_126.pdf'
Local $PDFViewer = "C:\Program Files\SumatraPDF\SumatraPDF.exe"
Local $RunString = $PDFViewer & " " & $PDFFileName

;METHODS

Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)
    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
EndFunc

Func _Check_HighLit_row1()

MouseMove(246, 459)
sleep(500)
MouseClickDrag ( "LEFT", 246, 459, 508, 461)
Send("{CTRLDOWN}c{CTRLUP}")
Send("{PGUP}")
Send("{CTRLDOWN}f{CTRLUP}Power{SPACE}consumption{ENTER}")

Global $row1 = ClipGet()

    If $row1 Then
        MsgBox(0, "HighLit", $row1, 2)
    Else
        MsgBox(0, "Nothing", "No Data", 2)
    EndIf
EndFunc

Func _Check_HighLit_row2()

MouseMove(241, 482)
sleep(500)
MouseClickDrag ( "LEFT", 241, 482, 509, 481)
Send("{CTRLDOWN}c{CTRLUP}")
Send("{PGUP}")
Send("{CTRLDOWN}f{CTRLUP}Power{SPACE}consumption{ENTER}")

Global $row2 = ClipGet()

    If $row2 Then
        MsgBox(0, "HighLit", $row2, 2)
    Else
        MsgBox(0, "Nothing", "No Data", 2)
    EndIf

EndFunc

Func _Check_HighLit_row3()

MouseMove(247, 500)
sleep(500)
MouseClickDrag ( "LEFT", 247, 500, 507, 538)
Send("{CTRLDOWN}c{CTRLUP}")
Send("{PGUP}")
Send("{CTRLDOWN}f{CTRLUP}Power{SPACE}consumption{ENTER}")

Global $row3 = ClipGet()

    If $row3 Then
        MsgBox(0, "HighLit", $row3, 2)
    Else
        MsgBox(0, "Nothing", "No Data", 2)
    EndIf

EndFunc

Func _Check_HighLit_row4()

MouseMove(244, 534)
sleep(500)
MouseClickDrag ( "LEFT", 244, 534, 507, 534)
Send("{CTRLDOWN}c{CTRLUP}")
Send("{PGUP}")
Send("{CTRLDOWN}f{CTRLUP}Power{SPACE}consumption{ENTER}")

Global $row4 = ClipGet()

    If $row4 Then
        MsgBox(0, "HighLit", $row4, 2)
    Else
        MsgBox(0, "Nothing", "No Data", 2)
    EndIf

EndFunc

Func _Check_HighLit_row5()

MouseMove(210, 552)
sleep(500)
MouseClickDrag ( "LEFT", 210, 552, 506, 564)
Send("{CTRLDOWN}c{CTRLUP}")
Send("{PGUP}")
Send("{CTRLDOWN}f{CTRLUP}Power{SPACE}consumption{ENTER}")

Global $row5 = ClipGet()

    If $row5 Then
        MsgBox(0, "HighLit", $row5, 2)
    Else
        MsgBox(0, "Nothing", "No Data", 2)
    EndIf

EndFunc

Func _Check_HighLit_row6()

MouseMove(209, 589)
sleep(500)
MouseClickDrag ( "LEFT", 209, 589, 505, 591)
Send("{CTRLDOWN}c{CTRLUP}")
Send("{PGUP}")
Send("{CTRLDOWN}f{CTRLUP}Power{SPACE}consumption{ENTER}")

Global $row6 = ClipGet()

    If $row6 Then
        MsgBox(0, "HighLit", $row6, 2)
    Else
        MsgBox(0, "Nothing", "No Data", 2)
    EndIf

EndFunc

Func _Save()

    Global $End = FileOpen("PsData.csv", 2)
    FileWrite($End, ClipGet())
    FileClose($End)

EndFunc

;MAIN FUNCTION
Run($RunString)

_WinWaitActivate("ADC_126.pdf - [untitled] - SumatraPDF","")
Send("{CTRLDOWN}f{CTRLUP}Power{SPACE}consumption{ENTER}")

Call("_Check_HighLit_row1")
Call("_Check_HighLit_row2")
Call("_Check_HighLit_row3")
Call("_Check_HighLit_row4")
Call("_Check_HighLit_row5")
Call("_Check_HighLit_row6")

ClipPut($row1 & @CRLF & $row2 & @CRLF & $row3 & @CRLF & $row4 & @CRLF & $row5 & @CRLF & $row6)
MsgBox(0,"Please Work", ClipGet(),4)

Call("_Save")
Link to comment
Share on other sites

I'm going to vomit at what I see here... someone hold my hair...

MouseClickDrag to highlight text...

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

I'm going to vomit at what I see here... someone hold my hair...

MouseClickDrag to highlight text...

We can vomit together! :P

anythign you can suggest to help a noob then? I only started this language on monday

Link to comment
Share on other sites

Wouldn't it be easier to translate the PDF to a text file and then process the text file?

Search Google for "free pdf to text converter command line" and you will find something like this.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

PDF really needs an api; it's such a pain. If you can convert it to word, you will be better off...then you just need to grab the colection of tables, and loop through them.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

The input PDF remains unchanged. The tools extracts the text from the PDF and writes it to an output file. You then can easily process the output file or many of them.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...