FE 'tkGooie' Utilities


'File Managers' group


tkScriptApplicator utility

(FE = Freedom Environment)

FE Home Page > FE Downloads Page > FE 'tkGooies' Description Page >

FE 'tkGooies' 'FileManagers' Page > This Page

INTRODUCTION to 'tkScriptApplicator'

I have a set of about 450 'Nautilus' scripts that I find quite handy to use for computing activities in many categories. In fact, I have the scripts stored in directories whose names indicate the areas of functionality:

  • AUDIOtools
  • EXAMINEfiles
  • FILESlists
  • FINDlists
  • IMAGEtools
  • LinuxHELPS
  • PROC-MEMlists
  • SPACElists
  • TERMtools
  • VIDEOtools
  • and more

I use those Nautilus scripts via the Nautilus file manager that was available in the Gnome 2 Linux desktop environment.

The general idea of 'Nautilus scripts':

You use the Nautilus file manager to navigate to a directory (for example, a directory of image files). Then you 'select-file(s)-and-apply-a-script-to-them'. Here is a little more detail on how it works.

You select the file (or files) in the usual way (using Ctl or Shift keys to select multiple files). Then, to select-and-apply a script, you right-click on the file-manager window. A menu including a 'Scripts' option pops up. When you move the mouse cursor over the 'Scripts' option, a hierarchical structure of scripts may be displayed --- scripts in sub-directories where the sub-directories can have names like those in the list above.

When you click on a script that appears in the menu hierarchy, the script is executed, with the file (or files) you selected passed as arguments to the script.

Here is an example that shows what the 'Nautilus scripts' hierarchy of menus can look like.

Click on this image to see a full-sized version of this image
in another browser window.

In this case, I right-clicked on a file in the Nautilus window and the Nautilus menu popped up with the 'Scripts >' option showing in the menu. By simply moving the mouse cursor over that 'Scripts' line, another menu in the cascade opens up showing names of Nautilus scripts and/or names of sub-directories containing Nautilus scripts.

    (In Gnome 2, Nautilus assumed that the hierarchy of scripts started at the directory $HOME/.gnome2/nautilus-scripts.)

In my setup, subdirectory names like the ones listed above showed up. I moved the mouse cursor over the 'TERMtools' category (sub-directory name) and another menu in the cascade opened up --- showing the names of the several scripts in the 'TERMtools' category.

At that point, I could have clicked on the name of one of the scripts. The script would have started up and the menu cascade would disappear.

For example, I could have clicked on the script named


That script, as the name suggests, does not use the filenames passed to it, other than to determine the directory name that contains the selected file. That directory name is used to start up a terminal window with a shell prompt that is positioned at that directory as the 'current working directory'.

As the script-name suggests, the script starts up a 'Gterminal', using the 'gnome-terminal' command.


Here's the rub. Around 2010, the developers of the Gnome desktop environment came out with Gnome 3. They took a view of the desktop environment that essentially threw out what they considered a lot of bathwater --- but that bathwater included many babies.

The Nautilus 2.28 file-manager that I was using suffered some 'regressions'. Some of the handy features of the Nautilus right-click menu were deemed no longer worth supporting. For example, the 'Open With > Other Application ...' option of the menu no longer worked in releases of Nautilus soon after the 2.28.1 version.

Not only 3.x versions lacked formerly provided handy capabilities, but even some 2.x versions after 2.28.1 suffered 'regressions'.

I became concerned about the loss of capabilities, especially loss of the 'Nautilus scripts' capability --- which was never even mentioned in press-releases, articles, reviews, etc. about Gnome 3.

I was not the only one concerned. Some Gnome 2 users in Argentina were so concerned that they forked the Gnome 2 desktop environment (with the Nautilus file manager that is central to that environment) to a new MATE (MAH-tay) desktop environment. They forked the Nautilus file manager to a file manager called 'Caja' (CAH-hah, Spanish for box).

(The 'Caja' file manager looks for 'Nautilus scripts' starting at the directory $HOME/.config/caja/scripts.)

Unfortunately, they forked Caja from a 2.x release that already included some regressions.

At that point, I realized that I could no longer depend on either Gnome 3 developers or MATE developers to preserve the 'Nautilus scripts' capability.

I realized that I could develop my own file(s)-selector --- along with a script-selector --- using Tcl-Tk to make the GUI's. In fact, around 2011, I created a system that I called 'feHappyScripts', as one of the subsystems of my Freedom Environment systems, available (for free) at www.freedomenv.com.

I rushed that system out, because I wanted the comfort of knowing that I could devise a Tcl-Tk system that provides the 'Nautilus scripts' capability.

That 'feHappyScripts' system is quite rough around the edges. It was basically a 'proof of concept' with a lot of unpolished code.

Even though it was unpolished, I was pleased to see that the Tk GUI listboxes could be filled with filenames even faster than the Nautilus file manager could present the names. For example, for directories containing more than 1,500 files, the names came up in a fraction of a second, whereas Nautilus took more than 5 seconds to complete showing the names.

This page is meant to provide a more polished implementation of a 'Nautilus scripts' capability --- using several Tk scripts.

For one thing, in my first pass at this, I used the 'ls -Ap' command to get the file lists with which to put directory names and 'regular' file names in the GUI's.

This time around I eventually decided to use the Tcl 'glob' command.

Furthermore, my first pass did not handle 'symbolic link' files --- for directories or for 'regular' files.

This time around, I wanted to at least make an attempt to handle 'symbolic links' --- even 'broken' links.

So here is a 'tkScriptApplicator' mini-system.


My two main goals for the 'tkScriptApplicator' mini-system were to provide two Tk GUI scripts:

  • a main 'file(s)-selector' Tk script

  • a 'script-selector' script, to be called by the 'file(s)-selector' GUI

In the process of developing the 'file(s)-selector' Tk script, I found that I needed one more Tk script:

  • a 'directory-selector' script, for a 'Jump2Dir' button on the 'file(s)-selector' GUI

This 'directory-selector' script was to also provide the option of editing a list of 'favorite directories'.

The two main Tk GUI's of this utility (the 'file(s)-selector' and the 'script-selector') could be implemented in many different ways.

For example, a SINGLE listbox could be used to hold both sub-directory names and filenames of a 'current directory'.

But I decided to use a TWO-listbox layout --- ONE listbox for sub-directory names and ONE listbox for 'regular' filenames.

I was influenced in this by a file-selector GUI that was used in a CAD/CAM/CAE system called 'I-DEAS' that was developed by SDRC (Structural Dynamics Research Corporation) of Milford, Ohio --- around 1990 to 2003.

    (SDRC and the I-DEAS software was eventually acquired by the company that developed the Unigraphics CAD/CAM/CAE software, around 2003 --- and Unigraphics was eventually acquired by Siemens, around 2008.)

In both the 'file(s)-selector' GUI and the 'script-selector' GUI, the TWO listboxes are side-by-side:

  • the LEFT listbox for the SUB-DIRECTORIES of the 'current directory' (specified at the top of the GUI)


  • the RIGHT listbox for the 'regular' (non-directory) files in the 'current directory'.

I should point out here that I was not especially interested in coming up with a 'beautiful utility'. I just wanted a utility that would make sure that I had a 'Nautilus scripts' capability --- a capability that is not subject to the whims and regressions of the Gnome 3 developers.

I am certainly interested in making pretty GUI's --- as my pages on Experiments in making embellished 'toolchest' GUI's and Version 2 of a demo of THEMES for Tk GUI's, using images and colors have indicated.

But at this time, I am satisfied to implement the 'functionality', and let the 'beauty' go for a later date (when I have more beauty tools/code at hand).


On the basis of considerations mentioned above, I ended up with the several GUI's seen in the following several images.

The 'file(s)-selector' GUI:

The 'script-selector' GUI --- which is called by the 'Apply-a-Script' button on the 'file(s)-selector' GUI:

The 'directory-selector' GUI --- which is called by the 'Jump2Dir' button on the 'file(s)-selector' GUI:

The list of sub-directories shown in this 'directory-selector' GUI is contained in a text file named 'fave_dirs.lis'.

The 'script-selector' GUI image above shows the main 'category' directories of my 'feNautilusScripts' --- which are available as a (free) package at www.freedomenv.com. However, the files-listbox is essentially empty, because my Nautilus scripts are in sub-directories of $HOME/.gnome2/nautilus-scripts.

Here is an image captured after I clicked on the 'IMAGEtools' subdirectory.

I use four-part script names that are described in a description of the 'feNautilusScripts' system at the www.freedomenv.com site.

One very pleasing aspect of the Tcl-Tk implementation is its speed. When I navigated to the directory '/usr/lib' with the 'file(s)-selector' GUI, the list of over 2,500 files was displayed in a fraction of a second. ("Blink and you miss it.")

It takes about 5 seconds for these files to be displayed in Nautilus --- at least the first time the directory is accessed. (It is faster in subsequent navigation to the directory in the same session.)

I suppose Nautilus is slower (in spite of it being a compiled program and the Tcl-Tk scripts being 'interpreted') because of overhead, such as showing, or trying to show, little image icons representing various types of directories and files.


Here is a quick overview of the operation of the 3 GUI's above.

  • 1)
    In the 'file(s)-selector' GUI, select one or more files to be provided to a script.

    If necessary, use the 'Jump2Dir' button to quickly navigate to a directory chosen from a list of 'favorites'.

    Further navigation is possible by single-clicks on the directories in the left listbox --- either click on '..' (to go UP to a parent directory) or click on a sub-directory name to go DOWN into that directory.

  • 2)
    Click on the 'Apply-a-Script' button of the 'file(s)-selector' GUI to bring up the 'script-selector' GUI --- by which to navigate to a suitable scripts subdirectory and choose a script.

  • 3)
    Click on the 'UseIt' button of the 'script-selector' GUI to execute the selected script according to the selected file(s).

    Clicking on the 'UseIt' button actually returns the script filename to the 'file(s)-selector' Tk script and exits the 'script-selector' GUI. It is the 'file(s)-selector' script that actually executes the selected script, providing the selected file(s) to that script.

  • 4)
    If the script was to make a new file in the current directory of the 'file(s)-selector' GUI, the user can click on the 'Refresh' button to re-fill the listboxes and make the new file visible.

Other options (such as Rename, Delete, Copy, Move, Properties, etc.) could be added (eventually) to the 'file(s)-selector' GUI to make it a more full-featured file manager.

But note that many functions that a user may want to perform can be implemented in Nautilus scripts. For example, a file-manager may be set up to play a '.mp4' file with the 'Totem' movie player when a user clicks on the '.mp4' file.

Alternatively, a user could have a Totem-player Nautilus script, say in a 'VIDEOtools' subdirectory. The user could click on the '.mp4' file in the 'file(s)-selector' GUI of this 'tkScriptApplicator' mini-system and choose to run the Totem-player script.


Below, I provide the Tk script code for the three Tk GUI's of this 'tkScriptApplicator' mini-system --- along with a 'fave_dirs.lis' text file to be used by the 'directory-selector' Tk script.

I follow my usual 'canonical' structure for Tk code for these 3 Tk scripts:

  0) Set general window & widget parms (win-name, win-position,
     win-color-scheme, fonts-for-widgets, widget-geometry-parms,
     text-array-for-labels-etc, win-size-control).

  1a) Define ALL frames (and sub-frames, if any).
  1b) Pack   ALL frames and sub-frames.

  2) Define & pack all widgets in the frames, frame by frame.
              Within each frame, define ALL the widgets.
              Then pack the widgets.

  3) Define keyboard and mouse/touchpad/touch-sensitive-screen action
     BINDINGS, if needed.

  4) Define PROCS, if needed.

  5) Additional GUI initialization (typically with one or more of
     the procs), if needed.

This Tk coding structure is discussed in more detail on the page A Canonical Structure for Tk Code --- and variations.

This structure makes it easy for me to find code sections --- while generating and testing a Tk script, and when looking for code snippets to include in other scripts (code re-use).

I call your attention to step-zero. One thing that I started doing in 2013 is use of a text-array for text in labels, buttons, and other widgets in the Tk GUI's that I author. This can make it easier for people to internationalize my scripts. I will be using a text-array like this in most of my Tk scripts in the future.

(I have put some of the info/warning/error messages in the text-array --- but I have left some messages hard-coded in the procs. I may someday put all the messages in the text-array assignment section of the Tk scripts.)

Experimenting with the GUI's

As in all my Tk scripts that use the 'pack' geometry manager (which is all of my 100-plus Tk scripts, so far), I provide the four main pack parameters --- '-side', '-anchor', '-fill', '-expand' --- on all of the 'pack' commands for the frames and widgets.

That helps me when I am initially testing the behavior of a GUI (the various widgets within it) as I resize the main window.

    I have never encountered a situation where I preferred to use the 'place' or 'grid' geometry managers of Tk, rather than the 'pack' geometry manager. I find the 'pack' geometry manager is more flexible in handling cases where I want to allow resizing the Tk GUI window.

I think that I have used a pretty nice choice of the 'pack' parameters for the 'file(s)-selector', 'script-selector', and 'directory-selector' Tk scripts.

The label and button widgets stay fixed in size and relative-location if the window is re-sized --- while the entry widgets expand/contract horizontally whenever the window is re-sized horizontally. And the listbox widgets expand/contract both vertically and horizontally when the window is resized in either direction.

You can experiment with the '-side', '-anchor', '-fill', and '-expand' parameters on the 'pack' commands for the various frames and widgets --- to get the widget behavior that you want.

Additional experimentation: You might want to change the fonts used for the various GUI widgets. For example, you could change '-weight' from 'normal' to 'bold' (if you have a screen resolution bigger than 1024x768) --- or change '-slant' from 'roman' to 'italic' --- or change the font sizes. Or change font families.

In fact, you may NEED to change the font families, because the families I used may not be available on your computer --- and the default font that the 'wish' interpreter chooses may not be very pleasing.

I use variables to set geometry parameters of widgets --- parameters such as border-widths and padding. And I have included the '-relief' parameter on the definitions of frames and widgets. Feel free to experiment with those 'appearance' parameters as well.

If you find the gray palette of the three GUI's is not to your liking, you can change the value of the RGB parameter supplied to the 'tk_setPalette' command near the top of each of the 3 Tk scripts.

Some features in the code

There are plenty of comments in the code, to describe what most of the code-sections are doing.

You can look at the top of the PROCS section of the code of any of the 3 Tk scripts to see a list of the procs used in each script, along with brief descriptions of how they are called and/or what they do.

The main procs of the 'file(s)-selector' GUI are

  'fill_lists'  - fills the 'dirs' and 'fils' listboxes based on var DIRFILmask

  'get_subdirs_inCURdir_inclLinks' - called by 'fill_lists' proc
  'get_files_inCURdir_inclLinks'   - called by 'fill_lists' proc

  'get_selected_files' - uses selected relative-filename[s] to set 'FULFILnames'

  'navigate'    - changes dir in 'DIRFILmask' entry field & runs 'fill_list'

  'jump2dir'    - gets a new dir for dirfilmask; uses Tk script

  'selectANDapply_script'  - gets a script and applies it to 'FULFILnames' ;
                             uses Tk script 'scriptSelector_2listboxes.tk'

  'set_status_msg'    - puts supplied msg into the Status msg frame

  The following 6 procs for for the window/widget resizing buttons:

    'toggle_fontsize'       - called by the 'TogFontSize' button
    'toggle_ybars'          - called by the '<-Ybars->' button

  'popup_msgVarWithScroll' - used to show the $HELPtext var ; also used
                              to show user various popup messages for
                              info, warnings, errors, etc.

One thing worth noting is the use of the -selectmode parameter on the various listbox definitions in the 3 Tk scripts.

In the 'file(s)-selector' script:

    We use '-selectmode single' on the 'dirs' listbox, but we use '-selectmode extended' in the 'fils' listbox --- because we want to allow the user to select multiple 'regular' files, but only one 'directory' file at a time.

In the 'script-selector' script:

    We use '-selectmode single' on BOTH the 'dirs' listbox and the 'fils' listbox --- because we want to allow the user to select only one script at at time, AND only one 'directory' file at a time.

In the 'directory-selector' script:

    There is only one listbox and we use '-selectmode single' because we want to allow the user to 'jump' to only one directory at a time.

Another thing worth noting is the implementation of the 'naroDir', 'wideDir', 'naroFil', 'wideFil', 'tallWin' and 'shortWin' buttons on the 'file(s)-selector' and 'script-selector' GUI's.

I find it frustrating to grab the edge of the window to resize it. It seems that the 'sensitive edge' is only about 1 pixel wide --- perhaps a hold-over from the days when a 640x480 monitor was big.

By simply clicking on the 'naroDir', ... , 'shortWin' buttons, I can resize the listboxes (either width or height) with a minimum of frustration.

If you prefer the vertical-scrollbar of the 'dirs' and 'fils' listboxes --- of the 'file(s)-selector' and 'script-selector' GUI's --- to be on the right rather than the left, you can click on the '<-Ybars->' button --- to toggle the 'y-bars' right and left.

It is my hope that the copious comments in the code will help Tcl-Tk coding 'newbies' get started in making GUI's like this.

Without the comments, potential young Tcler's might be tempted to return to their iPhones and iPads and iPods --- to watch hours and hours of 'fractal animation' videos --- until their minds turn to mush.

Here is a link to CODE for the Tk script 'tkScriptApplicator_multifilesSelector_2listboxes.tk'.

Here is a link to CODE for the Tk script 'scriptSelector_2listboxes.tk'.

Here is a link to CODE for the Tk script 'dirSelector_orEditListOfFavoriteDirs_1listbox.tk'.

Here is a link to a TEXT FILE of 'directory favorites' 'fave_dirs.lis'.


The 3 Tk scripts and the 'lis' file could be put in a sub-directory of the user's home directory, such as $HOME/apps/tkScriptApplicator.

Then the user can use their desktop system (such as Gnome or KDE) to set up the 'main' 'file(s)-selector' Tk script as an icon on the desktop.

Then, whenever the user wants to apply some Nautilus scripts to one or more files, the user can click on the icon to startup the main script of the 'tkScriptApplicator' mini-system.

In addition, a few variables may need to be set in the Tk scripts.

In the 'file(s)-selector' Tk script, the statement

   set DIRFILmask "$env(HOME)/*"

at the bottom of that script can be changed to have the file(s)-selector GUI start up positioned at a different directory from the user's home directory.

In the 'script-selector' Tk script, the location of the 'Nautilus scripts' can be changed in a 'set DIRshellScripts' statement near the bottom of that script.

In the 'directory-selector' Tk script, the text editor can be set in a 'set EDITORtext' statement near the bottom of that Tk script.

Furthermore, the 'fave_dirs.lis' text file could be edited to start off with a set of 'favorite' directories suited to the user-installer.


The copious amount of code here lends itself to many possible enhancements. Some examples:

  • Add some buttons to the 'file(s)-selector' Tk script (such as Rename, Delete, Copy, Move, Properties, etc.) to make it a more full-featured file manager.

  • Move some of the info/warning/error messages into the 'aRtext' array.

  • Change from a 2-listbox format to a 1-listbox format, for both the 'file(s)-selector' Tk script and the 'script-selector' Tk script.


NOTE that even if you do not ever implement these scripts, there may be some code here that would be of use. For example, the code that implements the 'fill_lists' procs is a big step forward from the similar code of the 'dirview' script in the Eric Johnson book "Graphical Applications with Tcl & Tk", first edition (1996), page 225-226, Chapter 6 'Lists, Files, and Directories'.

The 'dirview.tcl' script in chapter 6 gives an example of using a 'foreach' loop to extract directories and non-directories from 'glob' output. But that code would have to be made more robust to handle 'symbolic links' properly --- and exclude special files like fifo, socket, and device files.

Another example: The code in the 'toggle_ybars' proc may be of interest to some Tcler's.


As I have said on several of my code-donation pages on wiki.tcl.tk ...

There's a lot to like about a utility that is 'free freedom' --- that is, no-cost and open-source so that you can modify/enhance/fix it without having to wait for someone else to do it for you (which may be never).

A BIG THANK YOU to Ousterhout for starting Tcl-Tk, and a BIG THANK YOU to the Tcl-Tk developers and maintainers who have kept the simply MAH-velous 'wish' interpreter going.

Bottom of the page for tkScriptApplicator --- a utility in the FE 'tkGooies' system, in the 'File Managers' group.

To return to a previously visited web page location, click on the
Back button of your web browser a sufficient number of times.
OR, use the History-list option of your web browser.
OR ...

< Go to Top of Page, above. >
< Go to FE 'tkGooies' Description page >
< Go to FE Home page. >

The code on this page was created in 2014 --- and posted 2014 Jul 29 at http://wiki.tcl.tk/40417.

This FE web page was created 2015 Jan 13 --- as a backup and alternative to the wiki.tcl.tk page.