I am trying to set up a "user command" on TeXStudio with the purpose of compiling with shell-escape and the LaTeX -> DviPs -> Ps2Pdf cycle.
This is what I have done to get shell-escape to work and produce PDF output. [Edit: This section edited: see explanation below]
Method 1. In TeXStudio preferences -> Build -> User Commands:
latexmk --shell-escape
latexmk -synctex=1 -interaction=nonstopmode --shell-escape %.tex
See screenshot: top user command, the two lines above are entered from left to right.

Method 2. At the top of my document insert the line:
% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]
This line induces TeXStudio to request authorization to compile with shell-escape. This setup has so far worked for me to invoke shell-escape and produce PDF output "on the fly".
By analogy, I tried the following:
Method 1b. User Command:
latex --shell-escape: dvips : ps2pdf : view-pdf
latex -synctex=1 -interaction=nonstopmode --shell-escape %.tex: dvips -o %.ps %.dvi: ps2pdf %.ps
Method 2b. Top of document:
% !TeX TXS-program:compile = txs:///latex/[--shell-escape]
But that does not work. Am I on the right track?
To provide context: my purpose is to be able to compile the code shown here: Recreating a guilloche with TikZ. The code relies on the tkz-fct package and apparently requires the use of shell-escape but does not support pdflatex, suggesting that the latex -> dvips -> ps2pdf route is a natural one to try. And it is the route recommended in the tkz-fct manual.
How to set user commands in TexStudio? is a tex-stackexchange question with a link to the TeXStudio doc, which addresses related problems, but not this particular one head-on.
The TeXStudio documentation is here:
http://svn.code.sf.net/p/texstudio/code/trunk/utilities/usermanual_en.html#SECTION02a
Edit: Explanation about my first edit. I initially wrote that I had been succesful with the following settings:
pdflatex --shell-escape
pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex
However, I had been running this command on documents that had this at the top:
% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]
And it turns out that this line overrules my user commands. This is stated explicitly in Harish Kumar's answer (thanks Harish!). Without this overruling line, my user command does not succesfully invoke shell-escape. However, replacing pdflatex with latexmk did invoke shell-escape without the overruling line. I have therefore edited my incorrect claim. Having said that, I do not know much about latexmk other than it seems to be working.
Epilogue: Read Harish Kumar's answer to see how to properly enter the commands. Another thing I have since discovered is that the spanner-shaped button allows you to select among existing commands and to combine several commands, in that way the proper separator will be added between commands. Lastly, if you read the various comments here you will see that one reason why I had a hard time getting this to work was because the LaTeX file I was trying to compile needs gnuplot and I didn't have gnuplot installed on my system, giving me the impression that my commands were not working when they were (after Harish's corrections they were working properly).


latexmk --shell-escapein the first box is just a name for the user command. It has nothing more to do. What you type in the second box is the executable command. So in first box you can type any name. – Feb 17 '14 at 13:44