Automate the opening of multiple folders in Thunar

I am constantly opening the same set of folders in Thunar.

Is there a way to automate their opening and placing as tabs in one instance of Thunar?

The method might involve:

  • A Thunar feature (perhaps through a plugin) that creates a “saved space”
  • An equivalent to the Windows trick of pressing ALT and dragging and dropping a folder icon, thus creating a shortcut (there’d be as many shortcuts as there are target folders but all in once place so you don’t have to go chasing after different target folders)
  • Terminal commands, which could be strung together for several target folders (I wouldn’t even mind having to issue each command separately).

I am tagging Xfce because that is my desktop. I don’t know that the question depends on the desktop being used.

Thank you.

Take a look here… :arrow_down:

Thunar documentation — xfce.org

:arrow_down:

2 Likes

Thank you. That will be very useful.

What if I have more than one set of folders (now working on project 1, and now 2)? Anything along the lines of the original posts three bullets?

Well, all I can advise you to do is read the full documentation at the link above. If it’s not in there, then I cannot help you. :man_shrugging:

You may be able to glean thunar’s command line options by issuing the following command in a terminal window. :arrow_down:

thunar --help

As for what you mean in that second bullet point, please note that not everyone here knows how things are done in Microsoft Windows. To myself, that platform is quite alien — I do know a lot about how it works under the hood, but that’s not the same thing as being able to use it.

What I do know however is that a Windows “shortcut” is only a GUI artifact, while in UNIX, we have symbolic links, which are a special type of file that works even outside of the GUI.

Anyway, there are several thunar plugins and related packages in the repository, as well as in the AUR. So if the manual and the help function cannot give you what you want, then it might be interesting to look around in the repo and the AUR.

One option with regard to different projects could for instance be to use two separate file managers. nemo should probably work well in XFCE as well.

What you want to do is

thunar folder1 folder2 folder3

In the preferences instruct thunar to open new thunar instances as tabs - then script your workspace

mkdir -p ~/.local/bin
printf '#!/usr/bin/bash\nthunar folder1 folder2 folder3 &\n' > ~/.local/bin/workspace
chmod +x ~/.local/bin/workspace

All you have to do is to open a terminal and execute the script

1 Like

Here you go … should be plain to see how to edit/add paths:

for j in $HOME/Downloads $HOME/Documents $HOME/Pictures; do thunar $j & done </dev/null &>/dev/null &

Perhaps better would be to use nohup, so as to allow the terminal window to close while thunar remains active. :arrow_down:

mkdir -p ~/.local/bin
printf '#!/usr/bin/sh\nnohup thunar folder1 folder2 folder3\nexit\n' > ~/.local/bin/workspace
chmod +x ~/.local/bin/workspace
1 Like

This worked! Thanks to you both, linux-aarhus and Aragorn.

1 Like

Thanks.

At first I thought for j in and do were human speak being spoken to me, dem Menschen. But I entered it into terminal, and it worked!

Looks as though j were being defined as a variable and later being invoked.

Is done doing the work of nnohup in Aragorn’s comment?

If the explanation is too complicated don’t bother. I know I have to learn the basics of bash script.

Yes. It should read something like this… :arrow_down:

for variable-name-here in value1 value2 value3 ; do command-here ${variable-name-here} ; done

If the values are a numerical or alphabetic set, then you can also define them as {1..5} (for values from 1 to 5) or {a..z} for values from “a” to “z” (in all-lowercase, depending on the value of LC_COLLATE in your user’s environment).

[nx-74205:/dev/pts/3][/home/aragorn]
[aragorn] >  for i in {1..9} ; do echo $i ; done
1
2
3
4
5
6
7
8
9

No. done is the keyword that ends a " for ... ; do ... ; done" loop.

nohup is a command that detaches a process XYZ from the invoking process, so that the invoking process — in this case, a command shell, which itself runs as a child process of a terminal window — can be terminated without causing the XYZ process to be terminated as well. See the man page… :arrow_down:

man nohup

It’s not specific to bash or zsh. It’s a standard command in all UNIX systems. :wink:


PS.: Don’t forget to mark the post with the solution, whichever post it is. It will properly mark the matter as solved and will close the thread in a couple of days. :wink:

1 Like

I did that.

But one more question please.

What should I do if a path has spaces or special characters as in:

~/dump (2)

I tried these in a terminal, but they did not work:

nohup thunar '~/dump (2)'
nohup thunar "~/dump (2)"
nohup thunar ~/dump\ (2)

The following worked, but it is the least convenient of all I thought of:

nohup thunar ~/dump\ '(2)'

If a path includes many spaces, then I’d have to enter as many back slashes. So with parentheses.

Any “one go” solution?

I guess another question. When I run a command starting nohup thunar, I get the results I want (i.e. thunar is started and loaded with target folders, and when I close the terminal emulator, thunar stays up).

But I also get this output to terminal:

nohup: ignoring input and appending output to 'nohup.out'

What does it mean? Should I follow the example and ignore it?

If you’d rather want separate windows - remove the checkmark for tabs in thunar

What the suggested examples do is

  • Create the folder ~/.local/bin - it is in your path.
  • Create a script in the bin folder
  • the script opens a sequence of sample folder names
  • whether one use one or the other is a matter of preference

It is a matter of preference if one want the terminal to close after execution - which is was the nohup does help to faciliate

SIGHUP (Signal Hang UP) is a signal that terminates a Linux process when its controlling terminal is closed. Using the nohup command is one way of blocking the SIGHUP signal and allowing processes to complete even after logging out from the terminal/shell.

for foldernames with spaces use quotation marks

The appended & allows the script to continue to exit - the nohup message can be ignored …

#!/usr/bin/sh
nohup thunar folder1 folder2 folder3 "folder 4" "folder 5/test" &
exit
1 Like

You have to escape the spaces and the special characters. Usually double quotes will be fine. As an example… :arrow_down:

nohup thunar "dump (02)"

You don’t need to include the ~, because it will start from your home directory by default. If on the other hand you do want to include the ~, then do it like so… :arrow_down:

nohup thunar ~/"dump (2)"

That’s just the command-line output of thunar, which is just verbosity. You can ignore that. :wink:

Now that I see it written out like that, it makes perfect sense to me. The ~ is not part of the actual path but has a special function. By enclosing it with quotation marks, I interfered with its work. Thanks very much.

For anybody else just learning this topic, I confirm that these also worked:

nohup thunar ~/"dump (2)/dump (3)"
nohup thunar "$HOME/dump (2)"
nohup thunar "/home/luna/dump (2)"

Where, for the last one, luna is (obviously) my home directory.

Yes, the ~ in a path denotes your home directory. It’s another way of writing $HOME or ${HOME}. :wink:

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.