Book a Demo

Author Topic: Giving back: clipboard substitute better than using e.g. IE  (Read 3201 times)

Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
I would have used Geert's clipboard replacement functionality but... local privilege issues and activeX controls so I ended up writing this, which is much faster than starting IE.

Note that the readback does not delete the "clipboard file" so it can be "pasted" multiple times.

Code: [Select]
const localFilePath = "D:\EAclipboard.txt"

sub testputScriptDataInLocalFile
putScriptDataInLocalFile "Hello World"
        ' use pipe delimiter for test to show whitespace e.g. tab if included in the test string
Session.Output ("Read back = |" & getScriptDataFromLocalFile &"|")
end sub

sub putScriptDataInLocalFile(dataString)
' Note: delete the file each time and recreate so that it starts empty
dim fileSystemObject
dim outputFile

set fileSystemObject = CreateObject( "Scripting.FileSystemObject" )
if fileSystemObject.FileExists(localFilePath) then
fileSystemObject.DeleteFile(localFilePath)
end if
set outputFile = fileSystemObject.opentextFile(localFilePath, ForWriting, True)
outputFile.write dataString
outputFile.close
end sub

function getScriptDataFromLocalFile()
' Note: by not clearing or deleting the file after a read it can be retried if necessary
dim fileSystemObject
dim inputFile

set fileSystemObject = CreateObject( "Scripting.FileSystemObject" )
if fileSystemObject.FileExists(localFilePath) then
set inputFile = fileSystemObject.opentextFile(localFilePath, ForReading, True)
getScriptDataFromLocalFile = inputFile.readAll
inputFile.close
else
getScriptDataFromLocalFile = ""
end if
end function

Hope that's useful to others...

Julian