Append text to a text file?

crazybrit
2007-02-03
2013-05-29
  • crazybrit
    crazybrit
    2007-02-03

    Could someone make a plugin for this?  I.E., type append, tab, choose from a .txt files that's indexed by launchy, tab, type a line of text, enter, and it gets added to the end of the file.  It would be helpful for keeping todo lists and such.

     
    • noroom
      noroom
      2007-02-04

      Hm, I don't think this is something Launchy should be able to do. For that, there's many calendar applications (I recommend Rainlendar) that look pretty on your desktop and can even keep a To Do list with checkboxes and everything. Try that =)

       
      • crazybrit
        crazybrit
        2007-02-11

        Yeah, but that's not really what I want at all.  It's nice just to be able to send a line of text to a file without being distracted from what I'm actually doing.

         
        • Canyon Russell
          Canyon Russell
          2007-07-02

          I agree with the crazybrit.

          I would love a "cat<tab>Notes.txt<tab>Go to the store on 3rd street" command in Lanuchy. even the ability to set a default file and leave out the Notes.txt<tab> part.

          If anyone figures this out, please post it!

          Thanks

           
          • Persist
            Persist
            2007-07-04

            As I mentioned, there are a variety of ways to go about this... here's a few quick and dirty...

            First off the command-line in cmd would be simply:

            echo your text to append<<yourtextfile.txt

            There's a blog entry I came across detailing how to setup a simple batch file and have it indexed by launchy to leverage this simple command:

            http://benkraal.wordpress.com/2007/05/16/launchy-append-text-to-a-file-from-anywhere/

            It's really simple though I'm sure there are better ways of handling it and using the Runny plugin could definitely be a big help once it's done being fixed up.

            After reading these posts and not being happy with the above solution I just wrote up a tiny vbscript really quick (read: no real error checking or anything beyond bare functionality requested):

            -----------
            Const ForAppending = 8

            Set objArgs = WScript.Arguments
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            If objFSO.FileExists(objArgs(1)) Then
                Set objFile = objFSO.OpenTextFile(objArgs(1), ForAppending)
            Else
                Set objFile = objFSO.CreateTextFile(objArgs(1))
            End If

            objFile.WriteLine objArgs(0)

            objFile.Close
            ------------

            put it in a text editor, pick an easy name (I use addln.vbs), save it somewhere convenient with the .vbs extension, add the folder it's saved in to launchy directing it to index .vbs files in that dir, rebuild the index and then try it out:

            addln TAB "put your text to append within quotes" filename.txt
            addln TAB "spend less time on the computer" c:\lists\todo.txt

            You can specify a path for the text file it should go in, but just putting the name of the file will put the file in the same directory that you saved the vbs in.  If the filename doesn't exist, it'll create the file and add your text as the first line, otherwise it'll append it as a new line at the end.  From the few lines of code you can see it's *extremely* basic and sloppy... I didn't even bother to put in the whole 1-2 lines of script it would take to check for both command line arguments being present, hehe.  Feel free to run wild with it or ask me to adjust it.  Running it this way it actually makes more sense to have different versions with the text file hardcoded in such as:

            addtodo.vbs -
            -----------
            Const ForAppending = 8
            Dim strTextFile

            Set objArgs = WScript.Arguments
            strTextFile = "C:\home\todo.txt"
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            If objFSO.FileExists(strTextFile) Then
                Set objFile = objFSO.OpenTextFile(strTextFile, ForAppending)
            Else
                Set objFile = objFSO.CreateTextFile(strTextFile)
            End If

            objFile.WriteLine objArgs(0)

            objFile.Close
            ------------

            that way just making multiple copies and reindexing after changing only the name of the file and the name of the text file on the 5th line enables you to just use things like:

            addtodo TAB "get groceries"
            addevent TAB  "my birthday"

            But what really beats that is using the former version in combination with the Runny plugin (download the newest version from the Runny Req thread in the forums... it was just updated):

            I just make different runny entries that look like this:

            addtodo | c:\home\addln.vbs "$1" c:\home\todo.txt
            addevent | c:\home\addln.vbs "$1" c:\home\events.txt
            addthought | c:\home\addln.vbs "$1" c:\home\thoughts.txt

            then I can use these Runny keywords/alias' without the quotes (and hassle of making more than one vbs):

            addtodo TAB get groceries
            addevent TAB my birthday
            addthought TAB I wish I had a clever thought atm

            They all get appended to the text files defined in Runny as above (or created if they don't exist)... you get to Runny options btw by right clicking on Launchy -> Plugins -> select Runny -> Hit the Plugin Options button. Unfortunately though the latest version of Runny works great, I think there's some debug code left in there which pops up dialog boxes but I'm fairly certain if it's not just a weird happening on my end that it will be corrected very shortly. 

            Hope this helps get you started at least a little.  There's really a vast amount you could expand on as far as formatting options, manipulation, adding unicode support, etc. etc. but that sounds more like a plugin's domain... for simple tasks like this, simple means should be employed to keep unecessary plugins from staying resident in memory.  While this is meant to be a temporary quick-fix solution to try, there are a few simple things you might want to add such as date/time stamps (objFile.Write Now) so let me know if you find it useful (or have a question/problem) and I or someone here can assuredly help you modify whatever means you decide to employ to get it to do what you want.

            Again, hope this helps a bit...

            Regards,

            Jason

             
            • Adam
              Adam
              2008-04-09

              I have a question, this may seem like a dumb question but please pardon me, i'm a noob at this programming thing. is there a way to subtract a line from a text file using the same or different ".bat" file. for example; say i am using a todo.txt file and i want to get rid of a line of text using launchy. could i create a "subtract.bat" file?

               
            • Ralph Woods
              Ralph Woods
              2008-04-10

              I tried everything on this thread, to no avail.

              The 'echo %*etc' method just appends squares to the files. In every one of those vbs scripts I got the same error popup:

              [erro]

              I thought the errors could be a matter of text formatting, so I tried saving it in ANSI, Unicode, UTC, etc. Nothing changed.

              What could be the matter? I'm using Launchy 2.0.

               
              • Ralph Woods
                Ralph Woods
                2008-04-10

                Err I forgot to paste the actual error:

                =====
                Windows Script Host
                -------------------
                Script: C:\program files\launchy\utilities\add.vbs
                Line: 1
                Char: 1
                Error: Invalid character
                Code: 800A0408
                Source: Microsoft VBScript compilation error
                =====

                I'm using this script:

                =====
                addtodo.vbs -
                -----------
                Const ForAppending = 8
                Dim strTextFile

                Set objArgs = WScript.Arguments
                strTextFile = "C:\home\todo.txt"
                Set objFSO = CreateObject("Scripting.FileSystemObject")
                If objFSO.FileExists(strTextFile) Then
                Set objFile = objFSO.OpenTextFile(strTextFile, ForAppending)
                Else
                Set objFile = objFSO.CreateTextFile(strTextFile)
                End If

                objFile.WriteLine objArgs(0)

                objFile.Close
                ------------
                =====

                I tried using it with and without the 'addtodo.vbs - (dashes)' part, but I get the same error.

                 
                • The script works just fine, did your remember to add a parameter to it (ie the actual text to add to the file)? If not, you will get the error you described. Here is a run log from my machine, after creating the script in c:\tmp and then starting a cmd box (Win-R, cmd.exe, cd \tmp):

                  C:\tmp>dir
                  Directory of C:\tmp

                  2008-04-13  19:44    <DIR>          .
                  2008-04-13  19:44    <DIR>          ..
                  2008-04-13  19:41               379 addtodo.vbs
                                 1 File(s)            379 bytes
                                 2 Dir(s)   3,877,519,360 bytes free

                  C:\tmp>addtodo.vbs test0

                  C:\tmp>dir
                  Directory of C:\tmp

                  2008-04-13  19:44    <DIR>          .
                  2008-04-13  19:44    <DIR>          ..
                  2008-04-13  19:41               379 addtodo.vbs
                  2008-04-13  19:44                 7 todo.txt
                                 2 File(s)            386 bytes
                                 2 Dir(s)   3,877,519,360 bytes free

                  C:\tmp>type todo.txt
                  test0

                  C:\tmp>addtodo.vbs test1

                  C:\tmp>type todo.txt
                  test0
                  test1

                  C:\tmp>addtodo.vbs test2

                  C:\tmp>type todo.txt
                  test0
                  test1
                  test2

                  C:\tmp>

                   
                  • Ralph Woods
                    Ralph Woods
                    2008-04-17

                    You were right, the text wasn't being appended, because the file was in Launchy's Utilities folder, and the script was having a problem with the spaces in the path, for the "Program Files" folder. I then surrounded the whole path in quotes and it worked. Thanks.

                     
      • elwood151
        elwood151
        2007-07-03

        Sure, there are a lot of apps for keeping To Do lists etc., but the feature crazybrit proposes would make launchy an even more powerful tool - the ONE to rule them all ;-)

        ToDo lists are only one interesting example, and I also second the proposition for such a plugin or other solution.

        Martin

         
    • Persist
      Persist
      2007-02-08

      This and many other requests could be covered by calling simple command line apps (no need for keeping plugins or other stuff in memory)... so what's really needed IMO is a plugin that allows for arguments you type in to be passed to such apps.  That combined with the magic words plugin being discussed in another thread (and maybe some support for using variables in setting them up so that arguments could be properly passed) would really extend the abilities of Launchy to do a huge amount (almost everything I could even think of) without any need for additional plugins being created for each simple task.

      Jason

       
    • stephencj
      stephencj
      2007-09-04

      This is great. However, using the Runny method at the end there I only get the first word of my text if I enter it without quotes. With quotes I get all the text but it would be nice without - as in your example. Any ideas?

       
    • Josh
      Josh
      2007-09-05

      The Runny plugin in the next release will be fixed.  With that, a .bat or .vbs file should do the trick nicely.  I might even add one to the release.

      Josh

       
  • sunchess
    sunchess
    2009-11-15

    And what should i do with encoding? All this staff goes thru cmd bat files, where dos encoding. And on windows there is win1251. Thats bad

    For example — there is a way to post notes to evernote with launchy (http://www.jeffsmall.com/2009/06/evernote-and-launchy-integration.html). But i cant do it with my russian language =)

    Can this be done with vbscript, for example? Because with mentiod here vbscripts russian language is fine.

     

  • Anonymous
    2012-09-27

    @jasonmez This is a bit of a longshot after 5 years but could someone help me with this?

    I have Launchy 2.5 with the Runner plugin (formally Runny?)

    I can get the secon VBS script working with Runner and if I use "" then the text appears in my desired file.

    But if I don't use the "" then I only get the first word.

    I think the problem is with the 'argument' that I'm using:

    | Name               | Programme                                                                                                | Arguments
    |add                    | C:\Users\huwinj1\Documents\Dropbox\Scripts and VBS\add.vbs  | $$

    Any help most welcome. Thanks