topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Sunday December 15, 2024, 7:11 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: Is FARR right for me? Requesting barebones JScript example  (Read 6866 times)

dreftymac

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 17
    • View Profile
    • Donate to Member
Hello FARR-folks!

I am impressed with FARR and I'd like a little help to
determine if FARR is the right tool for me.

I would like to be able to do a proof of concept script
using the Javascript API. I've read the documentation and
I am pretty certain this is possible, I just have not found
it yet.

=====================
Code: Text [Select]
  1. STEP1:
  2. Output the following strings to FARR results pane:
  3.  
  4. * Hello World!
  5. * Bonjour Tout le Monde!
  6. * Hola Mundo!
  7. * Guten Tag Welt!
  8.  
  9. STEP2:
  10. Allow the user to choose one item from the results pane.
  11. (e.g., user presses ENTER on Hola Mundo!)
  12.  
  13. STEP3:
  14. Take the text that the user selected and paste it into the
  15. previously-active window.
=====================

STEP3 is the one I need help with, the other steps are pretty
easy to figure out from the existing examples.

Also, I'd like to see an example of step3 where FARR launches
any arbitrary application and passes in whatever the user
chose as a cmdline argument to that application.

Any help you can provide will be appreciated, as it will be
a big step in deciding whether FARR is the right tool for
me and I can jump in here with a donation and some code to
possibly help others.

Thanks in advance,

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: Is FARR right for me? Requesting barebones JScript example
« Reply #1 on: June 25, 2008, 07:24 AM »
assuming you don't need to generate those strings dynamically through some computation, you can do what you want much much easier than what you might be thinking.

you can make a simple alias that does exactly what you want.

just go to options, alias tab, choose myaliases.alias and create a new alias titled whatever you want (like for example "helloworld")
and then in results make a list like this:
Hello World! | paste Hello World!
Bonjour Tout le Monde! | paste Bonjour Tout le Monde!

that's all there is to it.



now if you wanted to generate those strings using some algorithm or getting them from a website or something, then you would want to write a javascript plugin like you initially said.

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: Is FARR right for me? Requesting barebones JScript example
« Reply #2 on: June 25, 2008, 07:38 AM »
mouser: i think dreftymac's problem is if there's a way for a plugin to paste text on to the previous window, like it's possible through aliases... Does the SDK export this capability?

dreftymac

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 17
    • View Profile
    • Donate to Member
Re: Is FARR right for me? Requesting barebones JScript example
« Reply #3 on: June 25, 2008, 11:16 AM »
assuming you don't need to generate those strings dynamically

*slaps forhead*

Thanks, mouser, but the "hello world" strings were just an effort to keep this discussion very simple. I am not literally interested in how to paste "Hello World" in different languages using FARR ... (my javascript will be indeed doing fancy stuff, but first I gotta lay the foundation, hence the phrase "proof of concept").

Thanks for the *paste* tip, though, as the documentation only talks about using paste with date, time and date+time, so that's an interesting tidbit you've added. I will keep that in mind also.

Just to re-cap:
* This really is a question about Javascript (I promise), a specific example doing the three steps above would be nice;
* FARR aliases are definitely great, but those are already pretty well documented, and javascript examples exist for that, so feel free to omit that from this convo;
* I am also interested in calling an external program and passing what the user selected as a cmdline argument to that program. (alternate variation of STEP3)

The reason I'm asking is because none of the existing Javascript-based examples do all three, and I'm trying to figure out how much time/money/brain-power to invest in this tool. So far it looks good, but I'd really like a bare-bones-very-simple example to start from, doing all three steps as shown above. (also with the second variation of STEP3 would be ultra-super).

Thanks in advance,


czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • View Profile
    • My open-source online piano game
    • Donate to Member
Re: Is FARR right for me? Requesting barebones JScript example
« Reply #4 on: June 25, 2008, 12:53 PM »
Also, I'd like to see an example of step3 where FARR launches
any arbitrary application and passes in whatever the user
chose as a cmdline argument to that application.

Hi,
this can be done easily by activexobject. Look at my "upload plugin", where I call 7zip with arguments and also call FTP commands...
You can also take a look at my "shell plugin" ;)

#
STEP3:
Take the text that the user selected and paste it into the previously-active window

alias commands can be called also from javascript so you can use "paste" command there ;) but if you need UTF-8 (chinese characters etc) support then I would use activexobject instead => take a look at my "online czech to X dictionary" where I paste text to the clipboard (unfortunately I do not know how to paste it directly to last active window)

EDIT: if you wait I will make some example on friday ;)
My open-source online piano game: https://github.com/musicope/game
« Last Edit: June 25, 2008, 12:55 PM by czechboy »

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: Is FARR right for me? Requesting barebones JScript example
« Reply #5 on: June 25, 2008, 05:36 PM »
alias commands can be called also from javascript so you can use "paste" command there

just to reiterate and clarify:
any result command you can issue from an alias, like:
paste, showhtml, etc

you can run from a javascript plugin by calling
FARR->set_strvalue("launch","paste BLAH BLAH");



There was a suggestion that i hope we pursue soon to make a more generic javascript scripting system based on dqsd which would make it a LOT easier for people to make javascript-style mini-plugins/scripts, without having to go through the entire process of having a dll, etc.

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • View Profile
    • My open-source online piano game
    • Donate to Member
Re: Is FARR right for me? Requesting barebones JScript example
« Reply #6 on: June 27, 2008, 10:57 AM »
try this:
Code: Javascript [Select]
  1. // plugin script :
  2. displayname="barebone";
  3. versionstring="1.01.01";
  4. releasedatestring="23.6.2008";
  5. author="Oldrich Svec";
  6. updateurl="";
  7. homepageurl="";
  8. shortdescription="barebone";
  9. longdescription="";
  10. advconfigstring="barebone";
  11. readmestring="barebone";
  12. iconfilename="icon.ico";
  13.  
  14. aliasstr="bb";
  15. regexstr="";
  16. scriptregex="";
  17. regexfilterstr="";
  18. keywordstr="";
  19. scorestr="300";
  20.  
  21. // type
  22. UNKNOWN=0; FILE=1; FOLDER=2; ALIAS=3; URL=4; PLUGIN=5; CLIP=5;
  23. // Postprocessing
  24. IMMEDIATE_DISPLAY=0; ADDSCORE=1; MATCH_AGAINST_SEARCH=2;
  25. // search state
  26. STOPPED=0; SEARCHING=1;
  27.  
  28. function onSearchBegin(querykey, explicit, queryraw, querynokeyword,modifierstring,triggermethod){
  29.   skip_value = 0;
  30.   if(!explicit) {
  31.     if(aliasstr.indexOf(querynokeyword)!=-1) {
  32.       FARR.setState(querykey,1);
  33.       FARR.emitResult(querykey,aliasstr, aliasstr, iconfilename,ALIAS,IMMEDIATE_DISPLAY,300);
  34.       FARR.setState(querykey,0);
  35.     }
  36.     return;
  37.   }
  38.   FARR.setState(querykey,SEARCHING);
  39.   FARR.emitResult(querykey,"Hello World!","1" , iconfilename,UNKNOWN,IMMEDIATE_DISPLAY,1000);
  40.   FARR.emitResult(querykey,"Bonjour Tout le Monde!","2" , iconfilename,UNKNOWN,IMMEDIATE_DISPLAY,1000);
  41.   FARR.setState(querykey,STOPPED);      
  42. }
  43.  
  44. HANDLED=1; CLOSE=2;
  45. function onProcessTrigger(path, caption) {
  46.   switch (path) {
  47.     case "1":
  48.       FARR.setStrValue("launch", "paste Hello World!")
  49.       break;
  50.     case "2":
  51.       var shell = new ActiveXObject("WScript.Shell");  
  52.       shell.Run("C:\\windows\\system32\\mspaint.exe \"C:\\windows\\system32\\ntimage.gif\"",1,true);
  53.       break;
  54.     default:
  55.       break;
  56.   }
  57.   return HANDLED;
  58. }
My open-source online piano game: https://github.com/musicope/game

dreftymac

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 17
    • View Profile
    • Donate to Member
Re: Is FARR right for me? Requesting barebones JScript example
« Reply #7 on: June 27, 2008, 12:43 PM »
try this:

SPLENDID!

That is precisely what I was looking for. Thank you very much, sir czechboy. May honor be upon your house for all days.

Thanks,