Throughout the articles I have published, I frequently refer to the use of the command line as a means to communicate with certain tools that do not have a graphical interface or GUI (General User Interface). Since some readers have expressed difficulties in using this mode of operation.
The example I will present is oriented towards Mac OS X, but it could be extrapolated to Linux, and to some extent to Microsoft environments.
To exemplify a specific situation, I will refer to the use of ArgyllCMS via the command line.
When we download the latest version of ArgyllCMS, upon decompressing we will find a directory structure:
- ref, which contains the reference files of some charts, the CHT files which are the descriptions of the patch distributions of the main charts on the market, and some other resources.
- bin, which is where the executable files, or binaries of ArgyllCMS, are contained
- libusb1, these are the drivers for the main spectrophotometers and colorimeters on the market, only interesting for Windows users, who must install these drivers to access their devices.
- doc, stores the documentation for the use of ArgyllCMS
To perform the first tests, we can start by accessing the bin folder and executing one of the binaries. Although first we must start our Terminal, which is usually found in the Utilities folder of our Mac OS X
The first difficulty for users is to know the path where we have saved or downloaded that folder; for this, we do a cmd+i on the folder in question and in the file properties the path will be shown as follows:
Location: /Users/jpereira/Downloads/Argyll_V1.4.0
In this way, from our terminal we can use the cd (Change Directory) command to access our folder:
cd /Users/jpereira/Downloads/Argyll_V1.4.0/bin
This way we will enter the “bin” folder.
If now we do, for example, an “ls -l” we will get the list of files in our directory as well as the permissions and users of each one; if we only did “ls” all files would be shown but without permissions or users.
For example, if now we do:
./scanin
We will execute the scanin tool, but since we do not provide any parameter, it will alert us of the error and indicate the available parameters and their usage:
Scanin, Version 1.3.4 Author: Graeme W. Gill, licensed under the AGPL Version 3 usage: scanin [options] input.tif recogin.cht valin.cie [diag.tif] :- inputs 'input.tif' and outputs scanner 'input.ti3', or usage: scanin -g [options] input.tif recogout.cht [diag.tif] :- outputs file 'recogout.cht', or usage: scanin -o [options] input.tif recogin.cht [diag.tif] :- outputs file 'input.val', or usage: scanin -c [options] input.tif recogin.cht scanprofile.[icc|mpp] pbase [diag.tif] :- inputs pbase.ti2 and outputs printer pbase.ti3, or usage: scanin -r [options] input.tif recogin.cht pbase [diag.tif] :- inputs pbase.ti2+.ti3 and outputs pbase.ti3 -g Generate a chart reference (.cht) file -o Output patch values in .val file -c Use image to measure color to convert printer pbase .ti2 to .ti3 -ca Same as -c, but accumulates more values to pbase .ti3 from subsequent pages -r Replace device values in pbase .ti2/.ti3 Default is to create a scanner .ti3 file -F x1,y1,x2,y2,x3,y3,x4,y4 Don't auto recognize, locate using four fiducial marks -p Compensate for perspective distortion -a Recognise chart in normal orientation only (-A fallback as is) Default is to recognise all possible chart angles -m Return true mean (default is robust mean) -G gamma Approximate gamma encoding of image -v [n] Verbosity level 0-9 -d [ihvglLIcrsonap] Generate diagnostic output (try -dipn) i diag - B&W of input image h diag - Horizontal edge/tick detection v diag - Vertical edge/tick detection g diag - Groups detected l diag - Lines detected L diag - All lines detected I diag - lines used to improve fit c diag - lines perspective corrected r diag - lines rotated s diag - diagnostic sample boxes rotated o diag - sample box outlines n diag - sample box names a diag - sample box areas p diag - pixel areas sampled -O outputfile Override the default output filename & extension.
If we look at the first part of this help, it indicates how we must place the sequence of parameters so that our tool understands them properly:
usage: scanin [options] input.tif recogin.cht valin.cie [diag.tif]
What does this mean?
1º we call the program; we will see later why in this example we do not use “./” to execute the tool.
2º [options] it tells us that in this part we will write the available options or parameters (pay attention to uppercase and lowercase in the syntax), so we could write in this area:
scanin -o -a
3º The third option is our tiff file so that:
scanin -o -a myImage.tiff
And at this point, we face the need to become familiar with tracing paths to our files, so if we only write “myImage.tiff”, it would be the case that our image is in the directory where we have previously located ourselves with “cd”
If the image were in a higher directory we would have to do:
../myImage.tiff
If, on the other hand, our image is elsewhere on our disk, we must trace the absolute path so that:
/Users/jpereira/Desktop/myImage.tiff
This often poses the difficulty or tedium of writing or determining the correct path. For this, all terminals have the feature of being able to autocomplete paths using the tab key, so if we type “/Us” and press tab, it will complete to /Users/, if on the other hand we are not sure how to continue the path, if we press tab several times, the possible alternatives will be shown, thus avoiding errors when writing a path. If when writing a path, tab is unable to complete it, it means there is some problem in our syntax.
If we continue interpreting the parameter sequence of our terminal, we see that we have to define “recogin.cht valin.cie”, these files are on the one hand the description of our color chart (-cht) and the reference file with the colorimetric data of our chart (.cie).
These files, or part of them, are located in the “ref” directory which is one level above, so we could have the following situation:
scanin -o -a /Users/jpereira/Desktop/myImage.tiff ../ref/ColorChecker.cht ../ref/ColorChecker.cie
Finally, we have to define the characteristics of the diag.tiff file, indicating that whenever instructions are in brackets “[…]” it means that it is optional, so we can leave it undefined (not put anything)
In this way we can have:
scanin -o -a /Users/jpereira/Desktop/myImage.tiff ../ref/ColorChecker.cht ../ref/ColorChecker.cie -dioa
This indicates that the parameter “-d” is concatenated with the attributes i, o, and a whose explanation is shown in the help. Whenever a parameter requests an attribute, it is exposed next; some tools require concatenation, and others may be separated by a space, for example “-G 2.2”
As we see, although a bit tedious, the command line does not demand much more than reading the documentation of each tool.
How to install these tools on our OS?
A common problem when starting with the command line is that every time we want to use a tool we have to navigate to the folder where it is located. This really should not be the case, since we can either install these tools or binaries on our system, or introduce the path to this directory in our profile so that the terminal searches in a certain path every time we request a tool.
Personally, I have the tools installed on the system, so I avoid having them scattered across my disk; for this, it is better to have them installed in the /usr/bin/ folder. Since this directory is usually included in the Path, or profile of our terminal, every time we request a tool it will be enough to write its name or part of it and autocomplete it with tab to have it available. To copy the ArgyllCMS distribution to /usr/bin/ we must do:
sudo cp -r /Users/jpereira/Downloads/Argyll_V1.4 /usr/bin/
From this command, several things must be explained: on the one hand, the parameter “sudo” is responsible for authenticating us as superuser; when using sudo, our system administrator password will be requested next; in Linux, there is always a superuser, but sometimes in Mac it may not be created; to use the sudo command, we must always have this password correctly defined. The next command is “cp” (copy) with the attribute “-r” which indicates a recursive copy, essential when copying directories to copy everything inside them. If we do not want to complicate ourselves by copying our tools deep into our system, we can move them to any other directory and use the .profile file that I explain later to locate them easily.
Normally this should allow that by writing the name of our tool it is already available; however, the most common way for this to work is to copy all Argyll tools to the root of /usr/bin/, but this would create some disorder in this directory; it is best to leave all related tools in the same directory (in case one day we want to delete them), for this we must describe the path to the .profile file:
/Users/jpereira/.profile
In Linux it is usually located at the path
/home/jose/.profile
Personally, to edit files via terminal I always use the “vim” editor so it would be enough to do:
vim /Users/jpereira/.profile
Vim is a plain text editor, included in almost all Unix environments such as Mac OS X or Linux, and it presents some roughness when familiarizing ourselves with its use, so inexperienced users can run our Textedit:
/Applications/TextEdit.app/Contents/MacOS/TextEdit /Users/jpereira/.profile
From here we can add the following path:
export PATH=$PATH:/usr/bin/Argyll_V1.4/
If we do not want to install our tools in the root of our system, we can use the .profile file to indicate the location of the directory containing particular tools
Once our tools are locatable through the PATH, it is no longer necessary to execute them with “./mytool”, just write the name of the tool in the terminal.
Conclusions:
As we see, although the use of our terminal may seem somewhat complex, it ends up becoming trivial in our daily work once we become familiar with the basic commands and the basic parameters of our tools.
Attention must be paid to the fact that when working in the root of our system with the “sudo” command we have permissions to delete any vital file or directory for the functioning of our OS, so we must be a bit cautious.
One of the most common difficulties for inexperienced users is to orient themselves with directory navigation with the “cp” command and the concept of relative path and absolute path; it is advisable to do some practice along with the “ls” command to gain some skill in moving through our file system.
