banner
Previous Page
PCLinuxOS Magazine
PCLinuxOS
Article List
Disclaimer
Next Page

Xfce Power User Tips, Tricks & Tweaks: Working With Documents

by Paul Arnote (parnote)

At some point, everyone using a computer has had to deal with documents of one kind or another. Most of us have exchanged word processing files or spreadsheets. Most of us have either downloaded, viewed or created PDF files. All of us have dealt with plain text files of one kind or another.

With this month's Xfce Power User Tips, Tricks & Tweaks article, we'll look at ways to simplify working with various document files.


Printing Text Files

Invariably, at some point, you'll want to print out a plain text file. Normally, you could just open it up in a simple text editor, then print it out. But, with this Thunar Custom Action, we can actually skip that step, and print it right from Thunar itself.



Select "Configure Custom Actions..." from the Thunar "Edit" menu. On the first line, provide a name for your new Thunar Custom Action. I entered "Print Text File" as its name. On the second line, enter a description. Keeping it simple, I entered "Print text file" as its description. On the third line, enter the following command:


yad --print --filename=%f --type=TEXT --add-preview

The --type=TEXT flag tells yad to print the specified file (--filename=%f) as a text file. If you used the --type=IMAGE flag, you could easily set up a similar custom action to print out image files. The --add-preview flag adds the "Print Preview" button to the Print dialog box. If you choose to omit this flag, only the "Print" and "Cancel" buttons will be displayed.

Next, select an icon for your new custom action. Under the "Appearance Conditions" tab, leave the "File Pattern" set to *, and place a checkmark in front of "Text files."

Now, when you right click on a plain text file, you can select "Print Text File" from Thunar's right-click context menu. When you do, you'll see the familiar "Print" dialog box, allowing you to select which printer to use.




Preview Text Files

Many times, you don't necessarily want to print a text file. You just want to browse its contents. Since I subscribe to the K.I.S.S. principle, I have a practice of keeping phone number lists and address lists in simple, plain text files. Lots of them. It's a method that I've used for years, and one that has always worked exceptionally well for me.

If I just want to look up someones address or telephone number, or just take a look at the contents of any other plain text file, I don't necessarily even have to open it up in a text editor. This Thunar Custom Action allows me to preview the first part of a text file in a dialog box on my screen, quickly and easily.



In configuring the Thunar Custom Action, provide a name and description. I entered "Preview Text File" for the name, and "Preview the selected text file" for the description. On the third line, enter the following command:

head -n 100 %f | zenity --text-info --width=450 --height=400 --title="Text Preview"

The command uses the head command to display the first 100 (-n 100) lines of the specified file (%f). You can change how many lines you want to be displayed simply by changing the number. For example, if you enter 20 (as -n 20), only the first 20 lines are displayed. Any text files less than the specified number of lines in length will simply be displayed in their entirety. The output from the head command is then piped into a Zenity text dialog box, with a width of 450 pixels, a height of 400 pixels, named "Text Preview."

Select an icon for your new custom action. Under the "Appearance Conditions" tab, leave the "File Pattern" set to *, and insure that only "Text Files" has a checkmark in front of it.



Now, whenever you right click on a text file and select "Preview Text File" from Thunar's context menu, your text file is displayed similarly to the example above. You can scroll through the contents, and when you are finished, just hit the Enter key (or click your mouse on the "Close" button).


Print Office Files

Besides text files, another common item printed out are office files. These are files commonly produced by "office suite" software, and includes word processing files, spreadsheets, database reports and any other type of common office files. Of course, you could always open the file in LibreOffice, but that's no longer necessary with this Thunar Custom Action. Why wait for LibreOffice to load if all you want to do is print out a document? All that is necessary is that LibreOffice must be able to open and render the file format.



Create a new Thunar Custom Action, and provide a name and description for it. I entered "Print Office File" for the name, and "Directly print files recognized by LibreOffice" as the description. Enter the following command on the "Command" line:

libreoffice3.6 --invisible -p %f

First, the libreofficeXX command must match the version of LibreOffice that you have installed. On this particular computer, I've not updated to LibreOffice 4.x yet, preferring to remain with LibreOffice 3.6. Once I do update to the most current version of LibreOffice, I will need to change my custom action commands to reflect the appropriate version of LibreOffice that is installed on my computer, due to the naming conventions used for the LibreOffice files.

The --invisible flag tells libreoffice3.6 to start without displaying the typical user interface or startup splash screens. The -p flag tells libreoffice3.6 that we merely want to print the designated file (%f) on the system's default printer (so be sure your default printer is set appropriately).

Now, choose an icon for your new custom action. Under the "Appearance Conditions" tab, place the following into the "File Pattern" field, and place a checkmark in front of "Other files."

*.doc;*.docx;*.odt;*.odp;*.pps;*.ppt;*.xls;*.xlsx;*.ods;*.pptx;*.pdf

When you right click on one of the above file formats, you will be able to choose "Print Office File" from Thunar's right click context menu and send that file directly to your default printer, without ever having to open LibreOffice.


Convert File To PDF

If you've ever needed to share a document with others, the difficulty becomes whether or not the receiving party has the appropriate file viewer. For a long time, no one but Microsoft Office users could open or view *.docx files – at least, until someone hacked the format. Meanwhile, Microsoft users might have some difficulty opening LibreOffice or OpenOffice files. Fortunately, there's an easy solution: just convert the file to a PDF file, which nearly everyone on any modern operating system can read. With this Thunar Custom Action, it's easier than 1-2-3.

The added benefit of distributing your document as a PDF is that it's not easily altered by the average Joe computer user. Thus, your document is typically viewed in the manner and formatting that you intended, and you don't have to worry that your document will be altered. The PDF format has gained a status that is pretty much universally accepted (despite its Adobe roots).



Create your new custom action. Give it a name and a description, respectively, on the first and second lines. I named mine "Convert To PDF" and provided "Convert the selected file to PDF" as the description. On the third line, enter the following as the command:

libreoffice3.6 --invisible --convert-to pdf %f

Remember that the number part of the libreofficeXX command must match the version of LibreOffice that you are running (same as in our last Thunar Custom Action). The -- invisible flag tells LibreOffice to not open the GUI to perform the specified action. The convert-to command tells it what format to convert to (pdf), and the %f is the file to perform the conversion to.

Select an icon for your new custom action. I used one of the Adobe PDF icons that wasn't already in use on my system. Then, enter the following for the "File Pattern" field:

*.doc;*.docx;*.odt;*.odp;*.pps;*.ppt;*.xls;*.xlsx;*.ods;*.pptx;*.txt

Place a checkmark in front of both the "Text files" and "Other files" for file types. Now, whenever you right click on any of the file formats above, you'll be able to choose "Convert To PDF" from Thunar's right-click context menu. The resulting PDF will be written to the same directory as your original file.


Convert To OpenDocument Text Format

Besides converting to PDF files, you can also convert from any other document format that LibreOffice can read into a native LibreOffice OpenDocument format – all without having to open the document in LibreOffice. For this Thunar Custom Action, I'll use the example of converting from *.doc and *.docx files to *.odt files, but you can easily create separate Thunar Custom Actions for converting from *.xls and *.xlsx files to *.ods files and so on.


Create your new Thunar Custom Action, and provide a name and description on the first two lines, respectively. I gave mine the name of "Convert To OpenDocument Text Format," and "Convert the selected file to an ODT file" as the description. On the third line, enter the following command:

libreoffice3.6 --invisible --convert-to odt %f

Remember to use the same number in the libreofficeXX command as the version of LibreOffice you have installed. Notice that the command is almost exactly like the previous command (where we converted the selected file to a PDF file), except that we now have selected the OpenDocument *.odt file as the format that we want to convert to.

Choose an icon for your new custom action. Under the "Appearance Conditions" tab, enter *.doc,*.docx as the "File Pattern" to match, and place a checkmark in front of "Other files."

Now, whenever you select "Convert To OpenDocument Text Format" from your Thunar's right click context menu, your selected file will be converted to an OpenDocument *.odt file. Just to be sure, I would recommend opening the new *.odt file to make sure that the conversion went well.

Also, don't forget that you can also make separate Thunar Custom Actions to convert from Excel spreadsheet formats (*.xls and *.xlsx) to the OpenDocument *.ods spreadsheet format. Since I don't deal with spreadsheets all that much, I didn't make the effort. However, I do know that there are some users out there that use spreadsheets a lot, and this variation on the Thunar Custom Action would be useful for them.


Summary

As you can see, there are quite a few ways to deal with document files, without ever having to really open the files. Whether it's just a plain text file, or if it's a complex word processing file, you can easily work with and manipulate the files right from Thunar, quickly and effectively.



Previous Page              Top              Next Page
Copyright (c) 2013, The PCLinuxOS Magazine. All Rights Reserved.