topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Saturday December 14, 2024, 11:46 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: FARR Scripting Problem: Getting plugin to close FARR inside onRegexSearchMatch  (Read 6340 times)

dreftymac

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 17
    • View Profile
    • Donate to Member
BACKGROUND:

    FARR: v2.10.01 by DonationCoder
    SCRIPT: fscript.js plugin script using the javascript plugin facility
    RUN PROFILE: calling farr.exe with the argument      -show -search ":myplugin";

SCENARIO:

I run farr using the prefix defined by my plugin as a commandline argument. All my plugin does is generate a list of suggestions
using FARR.emitResult. Then the user gets to pick one of the suggestions from the list. Once the user has chosen, the plugin
simply pastes what the user chose using the FARR "paste" command. This is done in the onProcessTrigger function of the jscript
file.

            FARR.setStrValue("launch", "paste "+path);           
            return CLOSE;

This works fine when the user types something that is already inside the suggestion list. If the user types something that is not
yet in the list, however, the script has to handle the input using onRegexSearchMatch function.

PROBLEM:
I am having trouble figuring out how to treat user input the same way inside the onRegexSearchMatch function. All I want to do
is take what the user typed and then paste it with the paste command. I have gotten this to work halfway, but FARR refuses to
dismiss when the user presses ENTER. It just sits there. Also, when FARR is started up again the next time, the input box is frozen
and wont accept keystrokes. The only way I have figured out how to dismiss FARR is to use FARR.debug(), which seems to make
FARR go away.

    function onRegexSearchMatch(querykey,querynokeyword) {
        var curr_match  =   null;
        curr_match      =   querynokeyword.match(scriptregex);
        if(curr_match[curr_match.length-1].toString() != ''){
            var stemp       =   '';
            stemp           =   curr_match[curr_match.length-1].toString().strip();

            // The paste works, but i dont want to have to use FARR.debug just to get the FARR window to close
            // Also, when FARR is started up again the next time, the input box is frozen and wont accept
            // keystrokes.
            FARR.setStrValue("launch", "paste "+stemp+"\n");                       
            FARR.debug('');
        }
    }



QUESTION:
What is the correct way to handle the scenario described here?

This is a step by step description of what I am trying to do.

1) Startup FARR so the prefix for my plugin is automatically filled into the search bar (doing that now with a script that calls FARR with command line args)
2) Allow the user to type in a string to be handled by my plugin
3) Generate a list of "suggestions" to the user, automatically generated by the plugin script
3) a) if the user input matches one of the auto-generated suggestions, take that input and just use FARR paste to get it into the last running app
3) b) if the user input does not match any of the auto-generated suggestions, match that input anyway and paste it into the last running app
4) keep track of whatever input the user supplied in either 3a) or 3b) and save it to a special history file
5) dismiss FARR window and make it wait in the background as usual

I can get all of the above steps to work as expected *except* for step 3) b) and step 5). When those two things happen together I cannot get FARR to exit normally nor startup and accept user input normally.

If you can help out, please do. Thanks.

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
I will post a detailed response tonight and if problems remain we can talk via email ([email protected]).

dreftymac

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 17
    • View Profile
    • Donate to Member
Just checking back ... in case Mouser is super super busy, does anyone else out there have an idea how to get scripting to work the way described above? I'm just looking to do a very simple example where FARR can accept and paste a user input string even if it is not in the list of script-generated auto-complete suggestions.

Thanks anyone out there who may have ideas on this.

~~~~

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • View Profile
    • My open-source online piano game
    • Donate to Member
try this, it works fine for me. Also you can define you own hotkey. Go to FARR settings/Hotkeys. Add new with "set search text bellow" checked only and in "text for search edit box" input "test\s". I have tested it with win+s  :Thmbsup:

EDIT: you can also check "copy selected text" and type into "text for search edit box" "test $$c" instead. So it would copy selected text and add it as input ;)
// plugin script :
displayname="Test";
versionstring="1.01.01";
releasedatestring="29.9.2008";
author="";
updateurl="";
homepageurl="";
shortdescription="Test";
longdescription="";
advconfigstring="Test";
readmestring="Test";
iconfilename="icon.ico";
aliasstr="test";
regexstr="";
regexfilterstr="";
keywordstr="";
scorestr="300";

// type
UNKNOWN=0; FILE=1; FOLDER=2; ALIAS=3; URL=4; PLUGIN=5; CLIP=5;
// Postprocessing
IMMEDIATE_DISPLAY=0; ADDSCORE=1; MATCH_AGAINST_SEARCH=2;
// search state
STOPPED=0; SEARCHING=1;

var qnk = "";

function onSearchBegin(querykey, explicit, queryraw, querynokeyword,modifierstring,triggermethod){
  if(!explicit) {
    if(aliasstr.indexOf(querynokeyword)!=-1) {
      FARR.setState(querykey,1);
      FARR.emitResult(querykey,aliasstr, aliasstr, iconfilename,ALIAS,IMMEDIATE_DISPLAY,300);
      FARR.setState(querykey,0);
    }
    return;
  }
  qnk = queryraw.replace(/^test /,"");
  FARR.setState(querykey,1);
  FARR.emitResult(querykey,"Not in list", "0", "Core-Farr.ico",5,IMMEDIATE_DISPLAY,674);
  FARR.emitResult(querykey,"hello", "1", "Core-Farr.ico",5,ADDSCORE,300);
  FARR.emitResult(querykey,"wall", "2", "Core-Farr.ico",5,ADDSCORE,300);
  FARR.emitResult(querykey,"dog", "3", "Core-Farr.ico",5,ADDSCORE,300);
  FARR.emitResult(querykey,"cat", "4", "Core-Farr.ico",5,ADDSCORE,300);
  FARR.setState(querykey,0);
}

function onProcessTrigger(title,path){
  if(path == "Not in list")
    FARR.setStrValue("PasteClipboardToLastActiveWindow", qnk);
  else
    FARR.setStrValue("PasteClipboardToLastActiveWindow", path);
}
My open-source online piano game: https://github.com/musicope/game
« Last Edit: October 12, 2008, 11:08 AM by czechboy »

dreftymac

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 17
    • View Profile
    • Donate to Member
That looks good and is a clever idea.

Thanks!