How to start CAJA with extra pane (F3)?

Hi!

Is there a solution to start CAJA automatic with extra pane?

When I close CAJA, it forgets that I pressed F3 key.

Restart CAJA, extra pane is gone.

Caja does not have feature unfortunately. I had a quick look in dconf-editor too, but there's nothing for extra pane.

Seems there is already a feature request created for it:


In the meantime, you can add an extra set of commands in place so Caja will launch and press F3 for you. This creates a script in place of where Caja is normally launched, so it works anywhere (like the Places menu).

Note that this only works:

  • until Caja is updated/reinstalled.
  • if the Caja window opens within half a second.

First move the original aside - we will create a script in its place:

sudo mv /usr/bin/caja /usr/bin/caja2
sudo nano /usr/bin/caja

Paste this:

#!/bin/bash
/usr/bin/caja2 $*
sleep 0.5
xdotool key --clearmodifiers F3

Save and make this script executable:

sudo chmod +x /usr/bin/caja

(Based on this)

You'll need to install xdotool:

sudo apt install xdotool

Normally a script like this should go in /usr/local/bin/ but it wasn't used when opening Caja via the MATE desktop.

I did:

sudo apt install xdotool

sudo mv /usr/bin/caja /usr/bin/caja2
sudo nano /usr/bin/caja

Pasted this into the file:

#!/bin/bash
/usr/bin/caja2 $*
sleep 0.5
xdotool key --clearmodifiers F3

Saved the file.

sudo chmod +x /usr/bin/caja

Run CAJA, extra pane is not there. :confused:

Try increasing the sleep to 0.75 or 1.

This script is a bit of a hack, but it's the only way for now. I can confirm it works on 18.04 LTS.

I give it up, did not work, so I removed it.

There was a script on a mint forms for thunar, it can be adapted for caja to open extra pane. And needed one more script to call it twice and close all the open caja windows.

Here it is:
cajatab
/usr/local/bin/cajatab

#!/bin/bash
# Script to open new file manager tab instead of window (e.g., Thunar) in XFCE. 
# Version 1. 2017-04-18

# Lock script to process multiple instances consecutively when "Open All" on Desktop. 
if [[ -d "${1}" ]]; then
	ME=`basename "$0"`;
	LCK="/tmp/${ME}.LCK";
	exec 8>$LCK;
	flock -x 8;  # lock $LCK
	trap 'rm -f $LCK' exit # remove $LCK regardless of exit status
	sleep .1 # hack to give time for each script to execute properly--weird!
fi

# Convert desktop file urls to thunar-friendly local paths. 
# Accommodates special characters in directory names (!@#$, etc).
fileurl="${1}"
filepath="$(urlencode -d ${fileurl%/})/"

# Check for running instances of $app on current desktop/workspace.
app=caja
wid=( $(xdotool search --desktop $(xdotool get_desktop) --class $app) ) 
lastwid=${wid[*]: -1} # Get PID of newest active thunar window.

# If $wid is null launch app with filepath.
if [ -z $wid ]; then
	$app "$filepath"
        
# If app is already running, activate it and use shortcuts to paste filepath into path bar.
else  
	xdotool windowactivate --sync $lastwid key F3 # Activate pane in caja 
	xdotool type -delay 0 "$filepath" # "--delay 0" removes default 12ms between each keystroke
	xdotool key Return
fi
exit 0

# Notice: These are instructions for thunartab, this is cajatab now :)

# Easy Installation: 
# cd ~/Downloads && tar -zxvf thunartab.tar.gz && sudo chmod 755 thunartab && sudo cp thunartab /usr/local/bin/
# Install dependencies: sudo apt install gridsite-clients xdotool # gridsite-clients contains urlencode 
# Reboot # if you want to run "thunartab" as a command in terminal
# Select script in the XFCE's GUI "Preferred Applications"
#
# For alternatives for script location run "echo $PATH" (without quotes) in terminal
# Troubleshooting: If more than one thunar window opens with "Open All", try increasing sleep value on line 12
# 
# For other file-managers (e.g., Nemo, Caja, Nautilus), change app name on line 21 
# You may also have to modified  the xdotool shortcuts on line 31.
# For example for Nemo, change line 31 to something like
# xdotool windowactivate --sync $lastwid key ctrl+t ctrl+l ctrl+v Return ctrl+l Escape
# Manually test shortcuts in file manager first. 
# 
# Main sources for learning bash for this script include: 
# http://ryanstutorials.net/bash-scripting-tutorial/ "Bash Scripting Tutorial" (Very good for beginners like myself"
# http://jdimpson.livejournal.com/5685.html "Using flock to protect critical sections in shell scripts"
# https://askubuntu.com/questions/55656/open-nautilus-as-new-tab-in-existing-window (the starting idea for this script)
#
# Bug reports or suggestions, please email me, Sam, at [email protected]

now it needs a wrapper which is goung to call the cajatab twice

cajatabwrapper change the path to whereever you put cajatab here
Had to change this script to close the caja open windows because it messes with all the open caja windows.

#!/bin/bash

# This script acts as a launcher for apps that observes the following rules:
#   1. If the app is not running, then start it up
#   2. If the app is running, don't start a second instance, instead:
#     2a. close it
#     2b. start the app

# Original script link: http://forum.xfce.org/viewtopic.php?id=6168&p=1

# there has to be at least one parameter, the name of the file to execute
if [ $# -lt 1 ]
then
  echo "Usage: `basename $0` {executable_name parameters}"
  exit 1
fi

BNAME='caja'

# test to see if program is already running
if [ "`wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $BNAME`" ]; then 
	# means it must already be running
	ACTIV_WIN=$(xdotool getactivewindow getwindowpid)
	LAUNCH_WIN=$(ps -ef | grep "$BNAME" | grep -v grep | tr -s ' ' | cut -d' ' -f2 | head -n 1)

		# close all the open caja windows
		for win in `wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $BNAME | cut -d' ' -f1`
		do
		    wmctrl -i -c $win
		done
fi

# start it up

for dir in "${@}"; do
     # Path to cajatab
    /usr/local/bin/cajatab "$dir"
done

exit 0

Wrapper closes all the open caja windows and calls the cajatab script.
cajatab starts caja and opens extra pane if two paths are passed to the wrapper script.

This command opens /home/user/Documents in caja:
cajatabwrapper $HOME/Documents

And next one opens $HOME/Downloads in extra pane and $HOME/Documents in first pane:
cajatabwrapper $HOME/Downloads $HOME/Documents

Required to have installed gridsite-clients, wmctrl and xdotool.

If you can improve this please share.

thanks @ Misko_2083! :slight_smile: