Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • December 03, 2016, 05:37:59 AM
  • Proudly celebrating 10 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 alias for choosing program based on file extension  (Read 2667 times)

wjamoe

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 74
    • View Profile
    • Donate to Member
FARR alias for choosing program based on file extension
« on: November 13, 2015, 09:31:46 AM »
Sometimes you don't want to start the default program for a certain file extension.

With the aliases below, you can pass the file name to start a program which you can select from your user defined menu.

Use it as follows:

First search and find the file using farr's search field or directory traversal.

Then select the file multiple times [Cursor Down] and then [Cursor Right] to display the file name in the farr search box.

Then press <dot>

Then select the program you want to run it with F1..F9, or use the [Cursor] keys.

To shorten the list of menu items you can enter a string after the dot,  then only lines matching the string and the file extension.




jump to latest version  http://www.donationc....msg394054#msg394054


Have fun :Thmbsup:
« Last Edit: March 12, 2016, 12:15:37 AM by wjamoe »

skajfes

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 231
    • View Profile
    • Donate to Member
Re: alias for choosing program based on file extension
« Reply #1 on: November 14, 2015, 01:15:33 PM »
Hi, I love this  :Thmbsup: . It's simple and effective.
However, I've modified it a bit to fit my needs better.
First I've changed the regex to (.+\.(.{3,4}))\s?(.*)$, and I've changed the result filter to $$2 $$3
This ignores the trailing space when you expand the filename so you don't have to backspace it after expanding the filename. It also allows to further filter the menu by typing in the tool you want. (ie. index.html opera)
This also simplifies the result list a bit, as you can just write $$1 everywhere for the full filename instead of $$1.$$2. Also it matches both 3 and 4 character extensions.
I like having the default program in the first place so I can just run it by pressing enter. I've found that just running the file directly has the best results for me, also running a program with just giving the name (see notepad example below), and without cmd.exe or shellexec

run default program for file: $$1 | "$$1"
notepad txt ahk bat ini ion pdf | C:\Program Files (x86)\Notepad++\notepad++.exe "$$1"
It is impossible to make anything foolproof because fools are so ingenious.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,405
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: alias for choosing program based on file extension
« Reply #2 on: November 14, 2015, 01:39:57 PM »
I'm not 100% following what's going on here -- which wouldn't be the first time I don't understand my own program :)

However i will just mention one thing, in FARR there is a help page under Advanced Use / Using Alias Action Keywords:

Code: Text [Select]
  1. A new feature with FARR version 2 is the ability to specify alias names in your search string using the + prefix (just like keyword modifiers).
  2.  
  3. When an alias name is specified in this way, anywhere on the search string, it does not effect search, but it will cause the alias results to be displayed AFTER the result file is selected, with the selected file name as argument $$1 in the alias.
  4.  
  5. In this way, you can perform a normal file/folder search and then launch a specific alias command with that file/folder as an ARGUMENT.
  6.  
  7. For example, you could create an alias named hexedit
  8. whose result contents are:
  9. C:\Program Files\HexEditors\HexEdit.exe "$$1"
  10.  
  11. Now you can type in your search (where mydocsearch is something like "C:\Users\myfile.txt"):
  12. mydocsearch +hexedit
  13.  
  14. As you type mydocsearch words, FARR will let you search for files as normal.
  15. After you choose the result, instead of launching the result file, you will be presented with
  16. C:\Program Files\HexEditors\HexEdit.exe "SELECTEDFILE"
  17. Which you can then launch.
  18.  
  19.  
  20. NOTE:
  21. You can use the same keyword for both alias names and search/scoring keyword modifiers.

This is specifically to let you use +keyword to open files that you have found using a non-default program.

The key thing here is that you define an alias as normal, using $$1 for the file to be opened, but then instead of triggering the alias normally by typing its name first, you use +aliasname in the search.

wjamoe

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 74
    • View Profile
    • Donate to Member
Re: alias for choosing program based on file extension
« Reply #3 on: November 14, 2015, 04:56:37 PM »
@skajfes, thanks for the optimisation  :Thmbsup:
I'll remove all shellex and cmd.exe's, they were needed in my very old version of farr, my bad  :-[, today I upgraded to v2.226.01 and assumed they were still needed.

I had to look up your PCRE :  (.+\.(.{3,4}))\s?(.*)$

$$1 contains file name including file name extension.
$$2 contains file name extension maximum length of 4 characters.
$$3 contains optionally for longer extensions 5th char and more followed by optional white space and optional characters that may contain more white space and dots.

----
I'm also working on a version where the alias
 
  • opens websites e.g. donationcoder.com without http:// prefix, but instead based on domain .com/.net/.org/.nl/.uk/.de/.be,
  • opens files like svg in a browser of your choice using file:///,
  • tags a file or url (grouping). Tagging is done by adding  tag at the end of the path\file.txt.tag (object oriented method notation). It
     uses separate files for each tag. These files are created dynamically. I use farr's #filecontents tag_file to retrieve the list of tagged files

For tagging I still need something like $$1.$$2 because I must be able to remove the temporary added extension tag =$$2 from the file name =$$1 before using it

The regex then becomes ((.+)\.(\S*))\s(.*)$

$$1 contains file name including extension
$$2 contains file name without extension and without trailing dot
$$3 contains extension without the dot (any length)
$$4 contains white space followed by any character, can be used as optional parameter in the program call if so required.

The farr (extension) alias filter thus becomes $$3

With this alias just add an entry to the farr alias results
     program name file extensions it can open followed by '|' the full path to the program and "$$1" in double quotes because file name can contain spaces

There are still some challenges (like searching within the list of tagged files), I'll send an update soonish. 8)

@mouser, in the hexedit example the user needs to know beforehand that he wants to edit the file in hex mode.
After searching and selecting a file from the farr results With the above alias you can choose any program (from the alias menu) including the default program for the file.
My alias is more similar to

With the above alias it is now fully integrated in FARR and can be performed without lifting your hands from the keyboard.
One additional advantage the program list will not change when some program hogs some or all file associations.
« Last Edit: November 14, 2015, 11:45:03 PM by wjamoe »

skajfes

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 231
    • View Profile
    • Donate to Member
Re: alias for choosing program based on file extension
« Reply #4 on: November 15, 2015, 03:47:38 AM »
I had to look up your PCRE :  (.+\.(.{3,4}))\s?(.*)$

$$1 contains file name including file name extension.
$$2 contains file name extension maximum length of 4 characters.
$$3 contains optionally for longer extensions 5th char and more followed by optional white space and optional characters that may contain more white space and dots.


Just to clarify:
$$2 contains file extension of 3 or 4 characters. It would probably be better if I set it like \S+ instead of .{3,4} to match any length of characters that has at least one character.
$$3 contains anything else that might be typed after the filename - this is used for additional filtering of the menu.


@mouser, in the hexedit example the user needs to know beforehand that he wants to edit the file in hex mode.
This is not quite true. You can search for files like you do normally, ie. start typing part of the filename. And when you see the desired file in the list you add +hexedit to the end of the search string. If you have only one result in the result list it will change to the alias text, ie: Edit <filename> with hexeditor. If you launch it it will open in hexeditor. However if you have multiple files in the result list, when you launch any of them it will open in hexeditor, however, the result list will not change.
It is impossible to make anything foolproof because fools are so ingenious.

wjamoe

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 74
    • View Profile
    • Donate to Member
Re: alias for choosing program based on file extension
« Reply #5 on: November 15, 2015, 06:23:47 AM »
1) I think my misunderstanding was caused when I used files with multiple dots, take a look at these

Code: Text [Select]
  1. (.+\.(.{3,4}))\s?(.*)$
  2. file.ex                NO MATCH =>okay extension to short
  3. file.extension         $$1=file.exte | $$2=exte | $$3=nsion => MATCH, but not what I expected
  4. filename.extension.mp  $$1=filename.exte | $$2=exte | $$3=nsion.mp => $$2 has value we cannot use
  5. file.ex.ED             $$1=file.ex.E | $$2=ex.E | $$3=D  => $$2 has value we cannot use (I assume that's why you use $$2$$3  as a filter )

I now use
Code: Text [Select]
  1. regex    ((.+)\.(\S+))\s?(.*)$
  2. filter      $$3 $$4
  3. The trailing text($$4) can be used to shorten the list of available programs e.g. add debug or -note or -))
  4.  
  5. file.sub.ext.mp4 debug  
  6.  
  7. To select the debug from the alias:
  8. debug ext menu  1full=$$1 2wo_ext=$$2 3ext=$$3 4filter=$$4  |
  9.  
  10. Where $$1=file.sub.ext.mp4 | $$2=file.sub.ext | $$3=mp4 | $$4=debug
  11.  
  12. Which displays as
  13. debug ext menu  1full=file.sub.ext.mp4 2wo_ext=file.sub.ext 3ext=mp4 4filter=debug

2) I stand corrected  :-[, Let me rephrase. You need to know the name of the alias, and have to type +hexedit, instead of selecting a program from a short list.

3) Still working on the file tagging functionality ;)

4) I have updated the first post so readers don't have to puzzle as much.
« Last Edit: November 15, 2015, 11:59:36 PM by wjamoe »

wjamoe

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 74
    • View Profile
    • Donate to Member
Re: alias for choosing program based on file extension
« Reply #6 on: December 27, 2015, 09:37:05 AM »
Update: 2 extended aliases!

Alias to add a farr "context menu" to a file in the farr search field
Alias to add a farr "context menu" to any string in the farr search field not containing a file extension

Each context menu is shown when you append a <space> and a dot and an optional menu match string.

example
farr search fieldc:\user\wim\my documents\test.txt .shows the complete list of menu lines matching extension txt to handle the file test.txt

example:
farr search fieldc:\user\wim\my documents\test.txt .noteshows a list of menu lines matching string 'note' to handle the file test.txt

descriptionalias for file names with extension like .doc, .txt, .ahk
usagefull path and file name including extension<space>.<result menu filter>
please notefull path and file name may contain spaces and dots,
easiest to copy result from farr search results (or directory traversing) by pressing Cursor-Right-key
aliasfile extension menu
regex ^((.+)\\(.+)\.(\S+))\s+\.(.*)$
filter$$5 $$4

usage within result(s)value
$$1<path>\<file name>.<file extension>
$$2<path excluding backslash at end>
$$3<file name excluding path and excluding extension>
$$4<file extension excluding preceding dot>
$$5<result menu filter>

usagedescriptionfarr result entry (copy only this part)
file_name .start default windows assocation[Enter] run default prog for -file.$$4 | shellexe $$1
file_name .vlc open  mkv avi and mp4 files with vlc[Enter]  VLC (mkv;avi;mp4) | %programfiles%\vlc\vlc.exe "$$1"
file_name .viewopen file with any extension in irfanview (image viewer)[Enter] / IRFANview -file.$$4 | %programfiles%\irfanview\i_view32.exe "$$1"
file_name .nppopen any file in notepad must include $$4 to match any file extension[Enter] notepad npp -file.$$4 | c:\windows\notepad.exe "$$1"
file_name .chroopen file in chrome browser use $$4  to match all file extensions[Enter] chrome -file.$$4 | %myAppData%\Google\Chrome\googlechrome.exe "$$1"
file_name .clcopy file name to clipboard[Enter]  FARR copy $$1 to CLIPBOARD  | copyclip $$1
file_name .stringshow lines within txt files (current folder and down) containing string using findstr in msdos box[Enter] find string '$$5' in *.txt /s | %systemdir%\cmd.exe /k findstr /S /I /P $$2 "$$2*.txt"
file_name.py .stringshow lines within files with same extension e.g. .py (current folder and down) containing string using findstr in msdos box[Enter] find string '$$5' in *.$$3 /s | %systemdir%\cmd.exe /k findstr /S /I /P "$$5" "$$2*.$$3"
file_name.doc .make subfolder file_name and move file_name.doc to subfolder, select this option from the result list[Enter] mv $$4-file to subFolder $$3 | %systemdir%\cmd.exe /c mkdir "$$2\$$3";;; %systemdir%\cmd.exe /c move /-Y "$$2\$$3.$$4" "$$2\$$3"

tip:
To always show a certain menu line when adding a dot in the search field, you should use the file extension ($$4) before the '|'.

tip:
The descriptive part before the '|' shouldn't be too long, otherwise the menu line gets cut up weirdly in the farr search results. Therefore use file_extension ($$4) instead of the full pathname ($$1)


A similar alias menu for strings / folders without extensions. This requires a different alias and regex. If you want to use both aliases the one matching no extensions should appear after the one matching extensions.

descriptionfor file names without extension
usageany string <space>.<result menu filter without spaces>
please notefull path and file name may contain spaces and dots
please noteeasiest to copy result from search results using cursor right key
aliasany string context menu
regex^(.+)\s+\.(.*)
filter$$2

Some examples of  FARR alias result entries
usagedescriptionfarr result entry
string or url .copy $$1 to clipboard[Enter] FARR copy $$1 to CLIPBOARD  | copyclip $$1
folder .show lines within files with same extension (current folder and down) containing string using findstr in msdos box[Enter] find string '$$2' in $$1*.* /s | %systemdir%\cmd.exe /k findstr /S /I /P "$$2" "$$1*.*"
string . look up string using duckduckgo.com [Enter] duckduckgo.com '$$1' |https://www.duckduckgo.com/?q=$$1
word . look up word using wikipedia [Enter] lookup  $$1 in WIKIPEDIA| https://en.wikipedia.../w/index.php?search=$$1&title=Special%3ASearch&go=Go

For wikipedia, copy text below, php table formatting removed some essential details of the wikipedia url.
[Enter] lookup  $$1 in WIKIPEDIA| https://en.wikipedia.../w/index.php?search=$$1&title=Special%3ASearch&go=Go


tip:
Sometimes pressing the cursor-right-key seems the correct action to execute the command from the new farr context menu, but this will give a strange result (the name of the alias will be copied to the search field). Therefore I placed [Enter] at the beginning of each farr alias result entry to make sure you press the [Enter] key. You can also double click the line and of course use the short cuts F1-F9 for the first nine entries.

tip:
If you edit the registry entries in my other post : how to start FARR from within explorer or total commander(TC). You can include a <space> and a <dot> at the end of the registry entry. When you then start FARR from within TC the above farr context menu will automatically appear. See underlined characters in registry :

[HKEY_CLASSES_ROOT\*\shell\FARR file\command]@="\"c:\\filemngr\\farr portable\\FindAndRunRobot.exe\" -search \"%1 .\""


Enjoy!  ;)
« Last Edit: March 08, 2016, 01:03:13 PM by wjamoe »

wjamoe

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 74
    • View Profile
    • Donate to Member
Re: alias for choosing program based on file extension
« Reply #7 on: December 29, 2015, 12:53:14 AM »
new/update:
Quote
file_name .string   
show lines within txt files (current folder and down) containing string using findstr in msdos box   
[Enter] find string '$$5' in *.txt /s | %systemdir%\cmd.exe /k findstr /S /I /P $$2 "$$2*.txt"

file_name.py .string   
show lines within files with same extension e.g. .py (current folder and down) containing string using findstr in msdos box   
[Enter] find string '$$5' in *.$$3 /s | %systemdir%\cmd.exe /k findstr /S /I /P "$$5" "$$2*.$$3"

Find lines in files containing a strings, similar to unix grep. Shows the  file names and lines containing the specified string using dos findstr command in an msdos box

Usage to  find search_string in files in current folder (path) and down (subfolders)

farr search fieldpath\filename.ext .search_string
or
farr search fieldpath .search_string

It will open an msdox box in a separate windows with the filenames and lines containing search_string.

BTW : It would be nice to get the result in the FARR results. I tried
[Enter] findstr '$$2' in *.txt | showmemo findstr '$$2' in '$$1*.txt' /s ;;; AppCapAppendMemoNS %systemdir%\findstr.exe /S /I /P $$2 "$$1*.txt"
but in popup it says bad invocation2 of quickdocklauncher.exe and gives an error '-0'

Does anyone know how to solve this problem?
« Last Edit: March 08, 2016, 12:37:09 PM by wjamoe »

wjamoe

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 74
    • View Profile
    • Donate to Member
Re: alias for choosing program based on file extension
« Reply #8 on: March 08, 2016, 12:58:42 PM »
File to Folder (by skwire) alternative using above FARR extension alias:

[Enter] mv $$4-file to subFolder $$3 | %systemdir%\cmd.exe /c mkdir "$$2\$$3";;; %systemdir%\cmd.exe /c move /-Y "$$2\$$3.$$4" "$$2\$$3";;; %systemdir%\cmd.exe /k dir "$$2\$$3"

make subfolder with name of file without filename extension
move file to file (ask for confirmation if you try to overwrite an existing  file)
shows contents of the subfolder without the extension in separate DOS window

or

[Enter] mv $$4-file to subFolder $$3 | %systemdir%\cmd.exe /c mkdir "$$2\$$3";;; %systemdir%\cmd.exe /c move /-Y "$$2\$$3.$$4" "$$2\$$3"

make subfolder with name of file without filename extension
move file to file (ask for confirmation if you try to overwrite an existing  file)


wjamoe

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 74
    • View Profile
    • Donate to Member
Re: alias for choosing program based on file extension
« Reply #9 on: March 08, 2016, 01:11:38 PM »
Sometimes when editing the search field this alias is triggered (too eraly) when the file name extension contains only one character.

By changing the regex

from
^((.+)\\(.+)\.(S+))\s+\.(.*)$

into

^((.+)\\(.+)\.(\S\S+))\s+\.(.*)$

the extension alias is only triggered when there are at least two characters in the file name extension (after the dot).

wjamoe

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 74
    • View Profile
    • Donate to Member
Re: FARR alias for choosing program based on file extension
« Reply #10 on: March 13, 2016, 04:28:26 AM »
run simple commands on the file in search window

just add
[Enter] run in DOS window $$5 $$4-file | %systemdir%\cmd.exe /k $$5 "$$1"

usage
c:\path somewhere on your disk\names.txt .sort
will start msdos window which shows the sorted lines from names.txt

c:\path somewhere on your disk\names.txt .notepad
to open file names.txt with notepad

other possible commands :
type, del, remove, cd, c:\path\par2, c:\path\unrar x, ...

wjamoe

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 74
    • View Profile
    • Donate to Member
Re: FARR alias for choosing program based on file extension
« Reply #11 on: July 19, 2016, 01:16:54 AM »
BIG speed optimization for the extension alias,
when using this you can use two spaces between filename and the command (instead of spaces and a dot)

replace

regex   ^((.+)\\(.+)\.(\S+))\s+\.(.*)$

by

regex ^((.+)\\(.+)\.(\S\S+))\s\s(\S*)

which reads as

anly line containing a '\'  (=this is part of the path of the filename)
some characters
a '.'  (=start of the file name extenstion)
at least two characters but not spaces (=file name extension, this helps when browsing for files)
 
followed by two spaces (=the separator between the file name and the command)

and a number of non-space characters (the command to look for in the extension alias)


For the filemanager shell extension, replace the dot by  a space):
so replace

HKEY_CLASSES_ROOT\*\shell\FARR file\command]   @="\"c:\\filemngr\\farr portable\\FindAndRunRobot.exe\" -search \"%1 .\""

by
HKEY_CLASSES_ROOT\*\shell\FARR file\command]   @="\"c:\\filemngr\\farr portable\\FindAndRunRobot.exe\" -search \"%1  \""


BTW the second alias for items without extensions is optional.

Njoy
Wjamoe
« Last Edit: July 24, 2016, 04:04:19 AM by wjamoe, Reason: TYPO IN REGEX LAST + SHOULD BE * »

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 6,136
  • Slartibartfarst
    • View Profile
    • Donate to Member
Re: FARR alias for choosing program based on file extension
« Reply #12 on: July 19, 2016, 02:16:56 AM »
Nifty! (Assuming it works - I haven't had time to try it yet.)    :Thmbsup: