topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday December 13, 2024, 9:25 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: help searching recipes.docx from farr?  (Read 5486 times)

ottenm

  • Supporting Member
  • Joined in 2008
  • **
  • default avatar
  • Posts: 93
    • View Profile
    • Donate to Member
help searching recipes.docx from farr?
« on: July 11, 2014, 02:11 PM »
I have a bunch of cooking recipes stored in a Microsoft Word document.  Each recipe has a title in bold and underlined, followed by plain text with the ingredients and instructions.  Ideally, I'd like to be able to search the recipes from FARR.  Maybe type something like "recipes chicken" into FARR and have the recipes that have "chicken" in their title show up in the results list.  When you select a recipe from the results list in FARR, it opens the ms-word doc to that page/recipe.  (Search by ingredients would be cool too, but feels pretty steep)

I are a good programmer and can write scripts, apps, vba macros, .... and the like.

The only thing I've found so far on the ms-word side is the ability to create a url that will open a document to a particular bookmark in that document.  Not a bad start, I can easily go through the doc and make each recipe title it's own bookmark.  But how to feed something like the list of bookmarks to FARR results?

Thanks for any suggestions, however tangential!

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: help searching recipes.docx from farr?
« Reply #1 on: July 11, 2014, 02:19 PM »
Interesting idea!

Here would be one way to solve this:

Write a utility that will scan your MS Word document and produce an output file that contains one line for each recipe.

You could EITHER make the tool output an alias file directly, or just output a simple text file that could be referenced using the "#filecontents" alias result.  The later might be easiest and each line of the file would be of the form LABEL | RESULT TO LAUNCH

The actual result that each line would launch would be your url that will open up the document to a particular bookmark.

With such a text file of results (one line for each recipe with the title being the words that would be searched for), you would then create a single alias called "recipes" and so typing "recipes chicken" would find all recipe results with the work chicken in them.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: help searching recipes.docx from farr?
« Reply #2 on: July 11, 2014, 02:20 PM »
See this thread for more on how to use the #filecontents trick: https://www.donation...ex.php?topic=17270.0

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: help searching recipes.docx from farr?
« Reply #3 on: July 12, 2014, 05:05 AM »
I like this idea ottenm, I hope you share whatever solution you end up with.  :Thmbsup: I'd like to add a third possible method: write a script that exports a link/URL to each recipe as separate .lnk files in some special folder. That is useful if you alternate between searching with FARR and some other tool like Everything, since both will find the recipe named .lnk files. I did something like that for Firefox bookmarks some years back here http://nod5.dcmember...ookmarkunpacker.html Maybe the general approach and some code bits can be reused if you like that method.

ottenm

  • Supporting Member
  • Joined in 2008
  • **
  • default avatar
  • Posts: 93
    • View Profile
    • Donate to Member
Re: help searching recipes.docx from farr?
« Reply #4 on: July 12, 2014, 06:36 PM »
Firstly, Mouser is clearly one of the greatest individuals of all time!  I hope it is known to anyone or anything that ever lives with Mouser that he is never to be hassled with thing like sock pickup, dish cleaning, or anything else at that level.

I was wrong about being able to open a MS-Word document scrolled to a particular bookmark.  I could only get it to work from hyperlinks inside Word documents, not from arbitrary/html url's outside Word.  "file:///recipes.docx#bookmark_name" opens the file, but ignores the bookmark.  Many fruitless hours of forum scanning behind this conclusion despite this dated KB article: http://support.microsoft.com/kb/310520.

Ultimately, I wrote a script to take the name of a bookmark on the command-line.  It opens recipes.docx scrolled to that bookmark.  RecipeOpen.vbs:

Option Explicit

Dim objWord
Dim currentDocument

set objWord = CreateObject("Word.Application")
objWord.DisplayAlerts = 0
objWord.visible = true
objWord.Documents.Open "c:\!projects\recipes.docx", false, False '(path, confirmconversions, readonly)

If WScript.Arguments.Count = 1 Then
set currentDocument = objWord.Documents(1)
   currentDocument.Bookmarks(WScript.Arguments.Item(0)).Select 'bookmark to bottom of screen
   objWord.ActiveWindow.LargeScroll 1 'scroll down 1 frame
   objWord.ActiveWindow.SmallScroll -3 'scroll back a few lines (bookmark to top of screen)
Else
   MsgBox "No bookmark name passed to RecipeOpen.vbs"
End If

objWord.Application.Activate 'move focus to ms-word ;(

Second script RecipeBookmarks.vbs scans my recipes.docx file for bookmarks and creates RecipeBookmarks.txt just as Mouser described above.  Each line contains: search text | url, such as "Top Drawer Seafood  Chowder  | c:\!Projects\RecipeOpen.vbs link20".  Got to remember to run this guy whenever I add a new recipe to the docx file.

Option Explicit

Dim objWord
Dim currentDocument
Dim bmk
Dim fs
Dim f

Set objWord = CreateObject("Word.Application")
objWord.DisplayAlerts = 0
objWord.Documents.Open "c:\!projects\recipes.docx", false, True '(path, confirmconversions, readonly)
Set currentDocument = objWord.Documents(1)

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.CreateTextFile("c:\!Projects\RecipeBookmarks.txt", True)

For Each bmk In currentDocument.Range.Bookmarks 'replace trims newlines
    f.WriteLine(Replace(bmk.Range.Text, vbCr, "") & " | c:\!Projects\RecipeOpen.vbs " & bmk.Name)
Next

currentDocument.SaveAs "c:\temp\recipes.htm", 8
currentDocument.Close
Set currentDocument = Nothing
objWord.Quit
Set objWord = Nothing
f.Close
Set f = Nothing

Lastly, inside FARR > Options > Aliases/Keywords/Groups I opened myaliases.alias and created a new Alias with the Trigger/Keyword set to "recipes" and the Result(s) set to "recipes | #filecontents C:\!Projects\RecipeBookmarks.txt".

Works like a charm!  Mouser for president!!

Thanks for all the great tools and support!

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: help searching recipes.docx from farr?
« Reply #5 on: July 12, 2014, 07:12 PM »
That's an awesome solution because others can use them to to work on any ms word file that uses bookmarks -- well done  :up:

Firstly, Mouser is clearly one of the greatest individuals of all time! I hope it is known to anyone or anything that ever lives with Mouser that he is never to be hassled with thing like sock pickup, dish cleaning, or anything else at that level.

Ha! I'll have to print that out in case I need it to help me get out of some chores  ;D