Internal File Associations Tutorial: Difference between revisions

From TotalcmdWiki
Jump to navigation Jump to search
Line 3: Line 3:
''Minimum TC version 7.55 required.''
''Minimum TC version 7.55 required.''


TC users who also use portable applications should be aware of TC’s internal file association feature, which makes using portable applications fun and easy. You can double-click a data file, say a .JPG file, to open it in its internally associated portable application, say IrfanView (your choice of portable freeware). With the free TC addon NiftyLink [http://ghisler.ch/board/viewtopic.php?t=27577] you can even create links to files, which are aware of TC's internal associations. I.e. double-clicking on such a link will open the respective file with the program, to which the file is internally associated in Total Commander. This is not possible with any standard Windows link, i.e. LNK file, symbolic link, junction, or hard link.
If you use portable applications you really should take advantage of TC’s internal file (and folder) association feature, which adds a custom menu to any file so you can open it in your portable application(s) with just a right-click. And even if you do not use portable applications, you could still benefit from this feature by adding a custom right-click menu to start installed applications, and custom right-click actions to files '''and folders'''. Some examples: Double-click a jpeg file to open it in portable IrfanView (your choice of portable freeware); Right-click a folder to open it in a new tab in the other panel.


While one can use TC’s menus to create and manage internal file associations, this tutorial shows how to edit .INI configuration files directly.
'''Note:''' ''While one can use TC’s GUI to create and manage internal file associations, this tutorial focuses on manually editing .INI configuration files directly.
The concepts involved apply equally well to the GUI case.''


So let’s start with the first step, which is to separate out the relevant .INI sections into their own file. By so doing, you end up with a self-contained '''set''' of definitions, which you could easily swap in and out of TC by simply renaming a file. We will name this file “associations-searches.INI”.
In the first step-by-step example, we will learn how to open an image file in a portable image viewer.
 
The first step is just general preparation, something we only need to do once and do not need to do for all associations that we will create. We take out from wincmd.INI the sections that deal with internal associations and save them into their own file. By so doing, we end up with a self-contained '''set''' of definitions, which you could easily swap in and out of TC by simply renaming a file. We will name this file “associations-searches.INI”.


=== STEP 1 – create searches-associations.INI ===
=== STEP 1 – create searches-associations.INI ===
Line 50: Line 53:


=== STEP 3 - associate “image” with IrfanView.INI ===
=== STEP 3 - associate “image” with IrfanView.INI ===
Edit section [Associations] of file associations-searches.INI and add the following lines:
Edit section [Associations] of file associations-searches.INI and add the following lines (you might need to replace ''Filter1'' with ''FilterN'', see the notes right under step 3):


  [Associations]
   Filter1=>image
   Filter1=>image
   Filter1_open=""%commander_path%\..\IrfanView\i_view32.exe" "%1""
   Filter1_open=""%commander_path%\..\IrfanView\i_view32.exe" "%1""
Line 60: Line 62:
''end of step 3''
''end of step 3''


Note two important points:
Note two important notes:


# You should substitute Filter1 with FilterN+1 if your searches-associations.INI file already includes other N filters, that is, use Filter3 for your new image association if there already are Filter1= and Filter2= lines in your .INI file.
# You should substitute Filter1 with FilterN+1 if your searches-associations.INI file already includes other N filters, that is, use Filter3 for your new image association if there already are Filter1= and Filter2= lines in your .INI file.
Line 66: Line 68:
# We have used %commander_path%\..\IrfanView\ to specify a relative folder path from TC’s own portable folder. This example assumes that TC’s folder is a sibling of IrfanView’s folder inside your main folder of portable applications.
# We have used %commander_path%\..\IrfanView\ to specify a relative folder path from TC’s own portable folder. This example assumes that TC’s folder is a sibling of IrfanView’s folder inside your main folder of portable applications.


Now you should verify that when you right click the icon of a .JPG or .PNG file TC’s menu shows '''Open (internal)''', which opens the file with IrfanView. Likewise, when you double-click an image file icon IrfanView should open.
Now verify that when you right click the icon of a .JPG or .PNG file TC display a menu with entry '''Open (internal)''', which opens the file in IrfanView. Likewise, verify that double-clickng an image file icon opens IrfanView.


Note that you only need to restart TC when you change section [Searches].
Note that you only need to restart TC when you change section [Searches].
Line 83: Line 85:
Again, you should substitute the right FilterN+1 for Filter1 in the example. Also, we have assumed that folder FSViewer is a sibling of TC’s own folder inside your main folder of portable applications.
Again, you should substitute the right FilterN+1 for Filter1 in the example. Also, we have assumed that folder FSViewer is a sibling of TC’s own folder inside your main folder of portable applications.


You should now verify that when you right click a .JPG or .PNG file icon TC’s menu shows ''open-FSViewer (internal)'', which opens the image file with FastStone Image Viewer. You may add more applications for the image file type by repeating step 4 for each application.
Now verify that right-clicking a .JPG or .PNG file icon displays a menu with entry ''open-FSViewer (internal)'', which opens the image file with FastStone Image Viewer. You may add more applications for the image file type by repeating step 4 for each application.


Let’s finish up our example by changing the icon that TC displays for the image file type. We will change it from IrfanView’s icon to FastStone’s.
Let’s finish up our example by changing the icon that TC displays for the image file type. We will change it from IrfanView’s icon to FastStone’s.
Line 102: Line 104:
You can now add more file types and associated applications by repeating steps 2-5.
You can now add more file types and associated applications by repeating steps 2-5.


=== Tips for effective use of internal associations ===
== Adding Right-Click Actions to Folders ==
 
Our next example creates a right-click menu entry that opens a folder in a new tab in the other panel. TC has an internal command to open the folder under the cursor in a new tab in the other panel '''cm_OpenDirInNewTabOther'''. This internal command works through TC's GUI, so we need a way to interact with TC's GUI from an internal association. A tool called TCFS2 is all we need for that.
 
=== STEP 1 - download and install TCFS2 ===
See the References section below for the link to TCFS. Download it and copy into folder "util\TCFS2" inside your Total Commander folder.
 
=== STEP 2 – create a search for folders ===
Edit section [Searches] of file associations-searches.INI and add the following lines '''as the first search''':
 
  ;FilterX=>dir
  ;FilterX-open-with-metapath=""%COMMANDER_PATH%\..\..\bin\Notepad2\metapath.exe" "%1""
  dir_SearchFor=
  dir_SearchFlags=0|000002000020||||||||22221|0000|
 
Save associations-searches.INI and restart TC.
 
''end of step 2''
 
This new search becomes available under the name ''dir'' in several TC dialogs, including the search dialog. The search matches all folders and no files.
 
=== STEP 3 - associate “dir” with cm_OpenDirInNewTabOther ===
Edit section [Associations] of file associations-searches.INI and add the following line:
 
  Filter2_open-dir-in-new-tab-other=""%COMMANDER_PATH%\util\TCFS2\TCFS2.exe" /ef "tcm(3004)""
 
Save associations-searches.INI and keep it open.
 
''end of step 3''
 
Verify that when you right-click a folder icon TC dispplay a meny with entry '''open-dir-in-new-tab-other (internal)''', which opens a new tab in the other panel and loads the folder under the cursor in the other tab.
 
=== Useful adds-ons ===
 
The free TC add-on NiftyLink [http://ghisler.ch/board/viewtopic.php?t=27577] allows creating "flexible links" to files. Such links are aware of TC's internal associations. Double-clicking a link icon opens the linked file in the program that is internally associated in Total Commander. This would not be possible with standard Windows links, like shortcut (.LNK) files, symbolic links, junctions, or hard links.
 
The free TC add-on TCFS2 [http://ghisler.ch/board/viewtopic.php?t=29700] allows controlling the Total Commander GUI from the command-line. With TCFS2 it is easy to run an internal command as an internal association of a file or folder (see above for an example).
 
=== Tips ===


# I like to keep the definition of a file type search and its corresponding file associations together, this way:
# I like to keep the definition of a file type search and its corresponding file associations together, this way:
Line 131: Line 171:


=== References ===
=== References ===
# [http://ghisler.ch/board/viewtopic.php?p=208215 forum thread]
# [http://ghisler.ch/board/viewtopic.php?p=208215 NiftyLink forum thread]
# [http://ghisler.ch/board/viewtopic.php?t=29700 TCFS2 forum thread]
# [http://www.ghisler.ch/wiki/index.php?title=Internal_File_Associations_Tutorial wiki tutorial]
# [http://www.ghisler.ch/wiki/index.php?title=Internal_File_Associations_Tutorial wiki tutorial]
----
----


Back to [[Tutorials]]
Back to [[Tutorials]]

Revision as of 20:28, 12 May 2012

How to use internal file associations effectively

Minimum TC version 7.55 required.

If you use portable applications you really should take advantage of TC’s internal file (and folder) association feature, which adds a custom menu to any file so you can open it in your portable application(s) with just a right-click. And even if you do not use portable applications, you could still benefit from this feature by adding a custom right-click menu to start installed applications, and custom right-click actions to files and folders. Some examples: Double-click a jpeg file to open it in portable IrfanView (your choice of portable freeware); Right-click a folder to open it in a new tab in the other panel.

Note: While one can use TC’s GUI to create and manage internal file associations, this tutorial focuses on manually editing .INI configuration files directly. The concepts involved apply equally well to the GUI case.

In the first step-by-step example, we will learn how to open an image file in a portable image viewer.

The first step is just general preparation, something we only need to do once and do not need to do for all associations that we will create. We take out from wincmd.INI the sections that deal with internal associations and save them into their own file. By so doing, we end up with a self-contained set of definitions, which you could easily swap in and out of TC by simply renaming a file. We will name this file “associations-searches.INI”.

STEP 1 – create searches-associations.INI

Explore TC’s configuration folder, where file wincmd.INI is located.

Create a new file named associations-searches.INI in that folder.

Open wincmd.INI and locate section [Searches].

  1. Copy the whole section from wincmd.INI to associations-searches.ini.
  2. Replace the whole section in wincmd.INI with these lines:


 [Searches]
 RedirectSection=associations-searches.INI

Do the same with section [Associations] in wincmd.INI – If you do not find such a section in wincmd.INI still make sure to add these lines to wincmd.INI:

 [Associations]
 RedirectSection=associations-searches.INI

Save wincmd.INI, keep associations-searches.INI open.

end of step 1

Let me point out that from now on every time you add a new search to TC that search will end up into associations-searches.INI, even though this search might not be linked to an internal file association.

The next step involves creating a new sample search, which we do want to link to an internal file association. Continuing on the .JPG example, we will create a search named image in step 2.

STEP 2 – create search “image”.INI

Edit section [Searches] of file associations-searches.INI and add the following lines:

 image_SearchFor=*.bmp *.gif *.jpg *.png *.psd *.tif
 image_SearchIn=
 image_SearchText=
 image_SearchFlags=0|000002000020|||||||||0000

Save associations-searches.INI and restart TC.

end of step 2

The new search becomes available under the name image in several TC dialogs, including the search dialog, but that isn’t why we created it. The main reason for creating this new search is to deal with a set of file extensions (bmp, gif, jpg, png, psd, tif) all at once by associating what Windows calls their file type with an application, like step 3 shows.

STEP 3 - associate “image” with IrfanView.INI

Edit section [Associations] of file associations-searches.INI and add the following lines (you might need to replace Filter1 with FilterN, see the notes right under step 3):

 Filter1=>image
 Filter1_open=""%commander_path%\..\IrfanView\i_view32.exe" "%1""

Save associations-searches.INI and keep it open.

end of step 3

Note two important notes:

  1. You should substitute Filter1 with FilterN+1 if your searches-associations.INI file already includes other N filters, that is, use Filter3 for your new image association if there already are Filter1= and Filter2= lines in your .INI file.
  1. We have used %commander_path%\..\IrfanView\ to specify a relative folder path from TC’s own portable folder. This example assumes that TC’s folder is a sibling of IrfanView’s folder inside your main folder of portable applications.

Now verify that when you right click the icon of a .JPG or .PNG file TC display a menu with entry Open (internal), which opens the file in IrfanView. Likewise, verify that double-clickng an image file icon opens IrfanView.

Note that you only need to restart TC when you change section [Searches].

Let’s now see how you can associate a second (third, etc…) application to your image type. We will use FastStone Image Viewer (portable freeware).

STEP 4 - associate “image” with FastStone Viewer.INI

Edit section [Associations] of file associations-searches.INI and add the following line:

 Filter1_open-FSViewer=""%commander_path%\..\FSViewer\FSViewer.exe" "%1""

Save associations-searches.INI and keep it open.

end of step 4

Again, you should substitute the right FilterN+1 for Filter1 in the example. Also, we have assumed that folder FSViewer is a sibling of TC’s own folder inside your main folder of portable applications.

Now verify that right-clicking a .JPG or .PNG file icon displays a menu with entry open-FSViewer (internal), which opens the image file with FastStone Image Viewer. You may add more applications for the image file type by repeating step 4 for each application.

Let’s finish up our example by changing the icon that TC displays for the image file type. We will change it from IrfanView’s icon to FastStone’s.

STEP 5 - change “image” file type icon.INI

Edit section [Associations] of file associations-searches.INI and add the following line:


 Filter1.icon=%commander_drive%\Portables\FSViewer\FSViewer.EXE

Save associations-searches.INI and restart TC.

end of step 5

When you change an icon you need to restart TC. Note that in step 5 we have used %commander_drive%\Portables\FSViewer\ instead of %commander_path%\..\FSViewer\ which we used in step 4. The two paths must lead to the same folder.

You can now add more file types and associated applications by repeating steps 2-5.

Adding Right-Click Actions to Folders

Our next example creates a right-click menu entry that opens a folder in a new tab in the other panel. TC has an internal command to open the folder under the cursor in a new tab in the other panel cm_OpenDirInNewTabOther. This internal command works through TC's GUI, so we need a way to interact with TC's GUI from an internal association. A tool called TCFS2 is all we need for that.

STEP 1 - download and install TCFS2

See the References section below for the link to TCFS. Download it and copy into folder "util\TCFS2" inside your Total Commander folder.

STEP 2 – create a search for folders

Edit section [Searches] of file associations-searches.INI and add the following lines as the first search:

 ;FilterX=>dir
 ;FilterX-open-with-metapath=""%COMMANDER_PATH%\..\..\bin\Notepad2\metapath.exe" "%1""
 dir_SearchFor=
 dir_SearchFlags=0|000002000020||||||||22221|0000|

Save associations-searches.INI and restart TC.

end of step 2

This new search becomes available under the name dir in several TC dialogs, including the search dialog. The search matches all folders and no files.

STEP 3 - associate “dir” with cm_OpenDirInNewTabOther

Edit section [Associations] of file associations-searches.INI and add the following line:

 Filter2_open-dir-in-new-tab-other=""%COMMANDER_PATH%\util\TCFS2\TCFS2.exe" /ef "tcm(3004)""

Save associations-searches.INI and keep it open.

end of step 3

Verify that when you right-click a folder icon TC dispplay a meny with entry open-dir-in-new-tab-other (internal), which opens a new tab in the other panel and loads the folder under the cursor in the other tab.

Useful adds-ons

The free TC add-on NiftyLink [1] allows creating "flexible links" to files. Such links are aware of TC's internal associations. Double-clicking a link icon opens the linked file in the program that is internally associated in Total Commander. This would not be possible with standard Windows links, like shortcut (.LNK) files, symbolic links, junctions, or hard links.

The free TC add-on TCFS2 [2] allows controlling the Total Commander GUI from the command-line. With TCFS2 it is easy to run an internal command as an internal association of a file or folder (see above for an example).

Tips

  1. I like to keep the definition of a file type search and its corresponding file associations together, this way:
 [Searches]
 ; ----- image
 ;FilterX=>image
 ;FilterX_open=""%commander_path%\..\IrfanView\i_view32.exe" "%1""
 ;FilterX_open-FSViewer=""%commander_path%\..\FSViewer\FSViewer.exe" "%1""
 ;FilterX.icon=%commander_drive%\Portables\FSViewer\FSViewer.EXE
 image_SearchFor=*.bmp *.gif *.jpg *.png *.psd *.tif
 image_SearchIn=
 image_SearchText=
 image_SearchFlags=0|000002000020|||||||||0000
 [Associations]

At this point, only the search for an image is defined, there is no internal association yet. To add an association append the four FilterX lines to section [Associations], delete the initial semicolon character, and replace X with the correct sequence number. This way of organizing your associations-searches.INI file is tidier when you need to renumber entries as in the next paragraph.

  1. To renumber (sort the order of) associations use TC’s File/internal associations dialog (drag and drop to sort items). Remember that when you double-click a file icon TC starts the application that is internally associated with the first file type (search) that matches the file extension.
  1. Use %commander_path% and %commander_drive% as the situation dictates. There are some portable programs out there that get confused when you use ..\ in the path. Such programs may not start correctly if you use %commander_path% but may start just fine if you use %commander_drive%, which usually doesn’t need to include ..\ path segments.
  1. I am in the habit of writing .INI entries this way:

Filter1_open=""%commander_drive%\path with spaces\app.exe" /option=value "%1""

Notice the numerous double-quotes. They are essential. The exterior left and write quotes match each other and enclose the whole item, which consists of three words: a quoted application path (with spaces), an option, and a quoted document path. In some cases you might need to write option="value" or even "/option=value" (quote the whole thing).

References

  1. NiftyLink forum thread
  2. TCFS2 forum thread
  3. wiki tutorial

Back to Tutorials