# [SOLVED] How to call the portable Tor Browser from cmd line

## vcmota

My question feels very basic and it probably is, but I have not been capable of sorting it out myself. I downloaded the portable Tor Browser, and to launch it every time I need to enter its folder and run 

```

~> cd tor-browser_en-US/

tor-browser_en-US> ./start-tor-browser.desktop

~> 

```

This is ok, but I would love it if I could just have instead an universal command, say MyTorBrowser, which I could call from any command line. Since I use DWM with dmenu, that would be great because it could than be launched from dmenu directly without the need of opening any terminal. To do this I first tried simply to include the tor folder in my PATH, which wont work because when launching the browser searches for files inside its folder assuming you are launching it from its folder. I tried a hard link with "ln" and after a simbolic link with "ln -s" and neither worked as well. 

I appreciate any help, thank you all.Last edited by vcmota on Thu Sep 12, 2019 4:05 am; edited 1 time in total

----------

## GDH-gentoo

 *vcmota wrote:*   

> 
> 
> ```
> ~> cd tor-browser_en-US/
> 
> ...

 

Is start-tor-browser.desktop a shell script, or a desktop entry file? What does file start-tor-browser.desktop say?

----------

## Hu

 *vcmota wrote:*   

> This is ok, but I would love it if I could just have instead an universal command, say MyTorBrowser, which I could call from any command line.

 So you want a shell script to wrap those two steps for you?

```
#!/bin/sh

cd "$HOME/tor-browser_en-US/" && exec ./start-tor-browser.desktop
```

 *vcmota wrote:*   

> I first tried simply to include the tor folder in my PATH, which wont work because when launching the browser searches for files inside its folder assuming you are launching it from its folder.

 This is confusing.  If it searches inside its directory (not folder), then how can it not find files inside its directory, since that is where it is searching?  Did you mean that it assumes the current working directory is the directory in which it was installed?  If so, that seems like a bug to me.  Users can run a program from anywhere, and the ability to find supporting files shouldn't depend on users to start in one particular directory.

----------

## Jaglover

Isn't the actual command line inside of that desktop file?

----------

## vcmota

 *GDH-gentoo wrote:*   

>  *vcmota wrote:*   
> 
> ```
> ~> cd tor-browser_en-US/
> 
> ...

 

Thank you GDH-gentoo for your reply. It is in fact a script:

```

tor-browser_en-US> file start-tor-browser.desktop

start-tor-browser.desktop: a /usr/bin/env ./Browser/execdesktop script, ASCII text executable

tor-browser_en-US>

```

but one which relies in running 

```
 /usr/bin/env ./Browser/execdesktop  
```

Anyway, after find out it was a script I opened it and that is what it is:

```

tor-browser_en-US> cat start-tor-browser.desktop

#!/usr/bin/env ./Browser/execdesktop

#

# This file is a self-modifying .desktop file that can be run from the shell.

# It preserves arguments and environment for the start-tor-browser script.

#

# Run './start-tor-browser.desktop --help' to display the full set of options.

#

# When invoked from the shell, this file must always be in a Tor Browser root

# directory. When run from the file manager or desktop GUI, it is relocatable.

#

# After first invocation, it will update itself with the absolute path to the

# current TBB location, to support relocation of this .desktop file for GUI

# invocation. You can also add Tor Browser to your desktop's application menu

# by running './start-tor-browser.desktop --register-app'

#

# If you use --register-app, and then relocate your TBB directory, Tor Browser

# will no longer launch from your desktop's app launcher/dock. However, if you

# re-run --register-app from inside that new directory, the script

# will correct the absolute paths and re-register itself.

#

# This file will also still function if the path changes when TBB is used as a

# portable app, so long as it is run directly from that new directory, either

# via the shell or via the file manager.

[Desktop Entry]

Type=Application

Name=Tor Browser Setup

GenericName=Web Browser

Comment=Tor Browser is +1 for privacy and -1 for mass surveillance

Categories=Network;WebBrowser;Security;

Exec=sh -c '"$(dirname "$*")"/Browser/start-tor-browser --detach || ([ ! -x "$(dirname "$*")"/Browser/start-tor-browser ] && "$(dirname "$*")"/start-tor-browser --detach)' dummy %k

X-TorBrowser-ExecShell=./Browser/start-tor-browser --detach

Icon=web-browser

StartupWMClass=Tor Browser

tor-browser_en-US>

```

So apparently it comes with a built in solution, which is just running

```

tor-browser_en-US> ./start-tor-browser.desktop --register-app

Launching './Browser/start-tor-browser --detach --register-app'...

Tor Browser has been registered as a desktop app for this user in ~/.local/share/applications/

tor-browser_en-US>

```

but, even after adding "~/.local/share/applications/" to my PATH the problem persists unless I am inside the tor folder:

```

~> start-tor-browser.desktop

/usr/bin/env: ‘./Browser/execdesktop’: No such file or directory

~>

```

Than I noticed that the script has been modified by the command "./start-tor-browser.desktop --register-app":

```

tor-browser_en-US> cat start-tor-browser.desktop

#!/usr/bin/env ./Browser/execdesktop

#

# This file is a self-modifying .desktop file that can be run from the shell.

# It preserves arguments and environment for the start-tor-browser script.

#

# Run './start-tor-browser.desktop --help' to display the full set of options.

#

# When invoked from the shell, this file must always be in a Tor Browser root

# directory. When run from the file manager or desktop GUI, it is relocatable.

#

# After first invocation, it will update itself with the absolute path to the

# current TBB location, to support relocation of this .desktop file for GUI

# invocation. You can also add Tor Browser to your desktop's application menu

# by running './start-tor-browser.desktop --register-app'

#

# If you use --register-app, and then relocate your TBB directory, Tor Browser

# will no longer launch from your desktop's app launcher/dock. However, if you

# re-run --register-app from inside that new directory, the script

# will correct the absolute paths and re-register itself.

#

# This file will also still function if the path changes when TBB is used as a

# portable app, so long as it is run directly from that new directory, either

# via the shell or via the file manager.

[Desktop Entry]

Type=Application

Name=Tor Browser

GenericName=Web Browser

Comment=Tor Browser is +1 for privacy and -1 for mass surveillance

Categories=Network;WebBrowser;Security;

Exec=sh -c '"/home/vinicius/tor-browser_en-US/Browser/start-tor-browser" --detach || ([ !  -x "/home/vinicius/tor-browser_en-US/Browser/start-tor-browser" ] && "$(dirname "$*")"/Browser/start-tor-browser --detach)' dummy %k

X-TorBrowser-ExecShell=./Browser/start-tor-browser --detach

Icon=/home/vinicius/tor-browser_en-US/Browser/browser/chrome/icons/default/default128.png

StartupWMClass=Tor Browser

tor-browser_en-US>

```

where you can see that "$(dirname "$*")" has been replaced by /home/vinicius/, so my full path. However as seen above that has not happened everywhere in the script, so I "corrected" it manually, adding the full path, and now the script reads:

```

~> cat ~/.local/share/applications/start-tor-browser.desktop

#!/usr/bin/env /home/vinicius/tor-browser_en-US/Browser/execdesktop

#

# This file is a self-modifying .desktop file that can be run from the shell.

# It preserves arguments and environment for the start-tor-browser script.

#

# Run './start-tor-browser.desktop --help' to display the full set of options.

#

# When invoked from the shell, this file must always be in a Tor Browser root

# directory. When run from the file manager or desktop GUI, it is relocatable.

#

# After first invocation, it will update itself with the absolute path to the

# current TBB location, to support relocation of this .desktop file for GUI

# invocation. You can also add Tor Browser to your desktop's application menu

# by running './start-tor-browser.desktop --register-app'

#

# If you use --register-app, and then relocate your TBB directory, Tor Browser

# will no longer launch from your desktop's app launcher/dock. However, if you

# re-run --register-app from inside that new directory, the script

# will correct the absolute paths and re-register itself.

#

# This file will also still function if the path changes when TBB is used as a

# portable app, so long as it is run directly from that new directory, either

# via the shell or via the file manager.

[Desktop Entry]

Type=Application

Name=Tor Browser

GenericName=Web Browser

Comment=Tor Browser is +1 for privacy and -1 for mass surveillance

Categories=Network;WebBrowser;Security;

Exec=sh -c '"/home/vinicius/tor-browser_en-US/Browser/start-tor-browser" --detach || ([ !  -x "/home/vinicius/tor-browser_en-US/Browser/start-tor-browser" ] && "/home/vinicius/tor-browser_en-US/Browser/start-tor-browser" --detach)' dummy %k

X-TorBrowser-ExecShell=/home/vinicius/tor-browser_en-US/Browser/start-tor-browser --detach

Icon=/home/vinicius/tor-browser_en-US/Browser/browser/chrome/icons/default/default128.png

StartupWMClass=Tor Browser

~>

```

and now it works! As you can see launching returns to errors

```

~> start-tor-browser.desktop

Launching '/home/vinicius/tor-browser_en-US/Browser/start-tor-browser --detach'...

~>

```

and Tor starts as it should, even when launching from dmenu. So besides my dumbness in the first place, it appears there is an error in their script. 

Thank you all for your help!Last edited by vcmota on Thu Sep 12, 2019 4:10 am; edited 1 time in total

----------

## vcmota

 *Hu wrote:*   

>  *vcmota wrote:*   This is ok, but I would love it if I could just have instead an universal command, say MyTorBrowser, which I could call from any command line. So you want a shell script to wrap those two steps for you?
> 
> ```
> #!/bin/sh
> 
> ...

 

Thank you Hu for your reply. The launching script apparently was planned to do all this work. However, as you may see in my larger reply, it was buggy, but not beyond manual repair.

----------

## vcmota

 *Jaglover wrote:*   

> Isn't the actual command line inside of that desktop file?

 

Thank you Jag Lover for your reply. No, apparently the actual command is in a folder inside the principal tor-browser folder, and that file is a simple script.

----------

## GDH-gentoo

 *vcmota wrote:*   

> Anyway, after find out it was a script I opened it and that is what it is:
> 
> ```
> 
> tor-browser_en-US> cat start-tor-browser.desktop
> ...

 

Huh. So this is both a desktop entry file and a script. That's creative, and bordering on mechanism abuse  :Laughing:  It has the format of a desktop entry file (of type Application), so the Tor browser can be launched by GUI programs that look for .desktop files in the applications subdirectory of ~/.local/share (or wherever $XDG_DATA_HOME points to) and understand their format. But lines that start with '#' are comments, and the first line is also a shebang line ("#!"), so if the file is executed, the kernel will invoke execdesktop as the interpreter.

I guess dmenu does not understand .desktop files, so it cannot do "GUI invocation", but instead one just configures program invocations somewhere. As Jaglover said, the actual command line is inside the file, it is in the Exec= line, after the file has "updated itself":

```
Exec=sh -c '"/home/vinicius/tor-browser_en-US/Browser/start-tor-browser" --detach || ([ !  -x "/home/vinicius/tor-browser_en-US/Browser/start-tor-browser" ] && "$(dirname "$*")"/Browser/start-tor-browser --detach)' dummy %k
```

If you don't move the "Tor Browser root directory" (/home/vinicius/tor-browser_en-US), the command you configure dmenu with to launch the Tor browser can be shortened to:

```
/home/vinicius/tor-browser_en-US/Browser/start-tor-browser --detach
```

----------

