Jump to content

Can't open reference file


therms
 Share

Recommended Posts

I'm sure this must be a bug in my script, but I can't for the life of me see it.

I'm working on the following UDF for adding new notes to Evernote.

The problem is that when I run it, it doesn't function correctly when any of the _EN_CreateNote parameters start with an "@" symbol. It doesn't add a note, and in the console (in Scite) is prints out Can't open reference file: followed by the text of the parameter starting with the @. (See following screenshot)

Posted Image

It's like the interpreter is trying to do something with the @ symbol, but I thought that wouldn't make any difference since it's in quote marks?

_EN_CreateNote("This is the text of a new note", "", "@next", "This is a test note title")


Func _EN_CreateNote($text = "", $file = "", $tag = "", $title = "", $notebook = "", $dttm = "")
    $ENexe = '"C:\Program Files (x86)\Evernote\Evernote3\ENScript.exe"'
    
    If @NumParams = 0 Then Return 1
    
    $file = _EN_CleanUpParameter($file)
    If Not $file = "" Then $file = " /s " & $file
    
    $tag = _EN_CleanUpParameter($tag)
    If Not $tag = "" Then $tag = " /t " & $tag
    
    $title = _EN_CleanUpParameter($title)
    If Not $title = "" Then $title = " /i " & $title
    
    $notebook = _EN_CleanUpParameter($notebook)
    If Not $notebook = "" Then $notebook = " /n " & $notebook
    
    $dttm = _EN_CleanUpParameter($dttm)
    If Not $dttm = "" Then $dttm = " /c " & $dttm
    
    If $text = "" Then
        $cmd = $ENexe & " createnote" & $file & $tag & $title & $notebook & $dttm
;~      ClipPut($cmd)
;~      MsgBox(0, "cmd", $cmd)
        $pid_EN = Run($cmd, "", @SW_HIDE)
        Return 0
    Else
        $cmd = $ENexe & " createnote" & $tag & $title & $notebook & $dttm
        
        $stdin_EN = Run($cmd, "", @SW_HIDE, 1)
        
        $chars_written = 0
        While 1
            If $chars_written < StringLen($text) Then
                $chars_written = StdinWrite($stdin_EN, $text)
            Else 
                ExitLoop
            EndIf
        WEnd
        Return 0
    EndIf   
EndFunc   ;==>_EN_CreateNote

Func _EN_CleanUpParameter($param)
    If StringInStr($param, " ") Then
        
        If StringLeft($param, 1) = '"' And StringRight($param, 1) = '"' Then
            Return $param
        Else
            $param = '"' & $param & '"'
        EndIf
        
    EndIf
    Return $param
EndFunc   ;==>CleanUpParameter
Link to comment
Share on other sites

I do not know of a good way to test sending @ via StdinWrite other than this:

AutoIt$pid = Run("cmd", "", @SW_SHOW, 1)
StdinWrite($pid, "cd temp" & @CR)
StdinWrite($pid, "@echo test | ConsoleRead.exe" & @CR)
StdinWrite($pid)

See the help file for the code to compile for ConsoleRead.exe

I did not get any errors sending the @ - but I also did not get the expected ouput piped to ConsoleRead.exe

Maybe someone will come to the rescue.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

I would do it like this instead:

Const $sENpath = @ProgramFilesDir & '\Evernote\Evernote3\ENScript.exe'

_CreateNote('New note inline', 'Test Body')
;MsgBox(0,"",@ERROR)

_CreateNoteFromFile('test.txt','New note from file')
;MsgBox(0,"",@ERROR)

Func _CreateNote($sTitle, $sBody, $sNotebook = "", $sTag = "")
    $sTempFile = @TempDir & '\EvernoteTemp.txt'
    FileWrite($sTempFile, $sBody)
    $rs = _CreateNoteFromFile($sTempFile, $sTitle, $sNotebook, $sTag)
    FileDelete($sTempFile)
EndFunc

Func _CreateNoteFromFile($sFilename, $sTitle, $sNotebook = "", $sTag = "")
    ;Make sure path is fully qualified
    $sFilename = FileGetLongName ($sFilename, 1)
    If NOT FileExists($sFilename) Then Return SetError(1,0,0)
    
    $sCommand = StringFormat('createnote /s "%s" /i "%s"', $sFilename, $sTitle)
    
    ;If notebook is specified, use it
    If $sNotebook <> "" Then $sCommand &= StringFormat(' /n "%s"',$sNotebook)
    
    ;If tag is specified, split by comma and append to command
    If $sTag <> "" Then
        $aTags = StringSplit($sTag, ",")
        For $X = 1 to $aTags[0]
            $sCommand &= StringFormat(' /t "%s"',$aTags[$X])
        Next
    EndIf
    
    $iExit = RunWait($sENpath & " " & $sCommand)
    
    ;Exit code 0 = Success
    If $iExit <> 0 Then Return SetError(2,0,0)
EndFunc
Edited by weaponx
Link to comment
Share on other sites

I would do it like this instead:

Ahh, thank you weaponx, that straightened out my thinking process on this.

With regards to my specific error, it turns out that specific error is a bug with Evernote's scripting utility. What I don't understand is how the error appeared in Scite's console when I didn't do any StdoutRead.

Link to comment
Share on other sites

Ahh, thank you weaponx, that straightened out my thinking process on this.

With regards to my specific error, it turns out that specific error is a bug with Evernote's scripting utility. What I don't understand is how the error appeared in Scite's console when I didn't do any StdoutRead.

Not sure. Stdout/stdin give me the willies.

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...