Я хочу иметь два совершенно других экземпляра Хрома, каждого с его собственным значком, так, чтобы:
Как я могу сделать это?
Решения я рассмотрел:
~/.local/share/applications/chromium-browser-2.desktop
указывая на него, с отдельным значком. Это показало отдельный значок в Тире, но при запуске его, он открыл мой существующий профиль Хрома, и окно все еще было смешано с существующими окнами Chromium. Похож на исполняемый файл, должно на самом деле отличаться в некотором роде?Что работало (починенный из различных ответов, и комментарии - Спасибо!) должен был создать a .desktop
файл в ~/.local/share/applications
с несколькими тонкими настройками:
[Desktop Entry]
Version=1.0
Name=Chromium Browser 2
GenericName=Web Browser 2
Comment=Chromium Alternate
Exec=/usr/lib/chromium-browser/chromium-browser --user-data-dir=/home/dandv/Chr2 --class="Chr2"
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=/home/dandv/chromium-browser-2.png
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml_xml;x-scheme-handler/http;x-scheme-handler/https;
StartupNotify=true
Actions=NewWindow;Incognito;TempProfile;
X-AppInstall-Package=chromium-browser
StartupWMClass=Chr2
Удостоверьтесь, что заменили /home/dandv/
с Вашим корневым каталогом. Используя ~
не работал.
Тонкие настройки я обратился .desktop
файл был:
--class="SomethingLikeChr2"
к Exec=
строкаStartupWMClass=SomethingLikeChr2
к [Desktop Entry]
(используйте то же уникальное значение как выше; по-видимому, это - то, что делает отдельное окно, которое не будет смешано в с существующими окнами Chromium--user-data-dir=...
к Exec
строка, из-за этой ошибки Хрома.Самым легким путем я знаю о, использует Больше Инструментов->, Создают Ярлык. Оттуда это создаст .desktop запись, что можно настроить значок, и можно перейти в chrome://apps
изменить настройки как открытие как окно.
WMClass, кажется, не имеет никаких полномочий когда дело доходит до Хрома... Я придумал это отвращение (личное мнение... Я был бы, точно так же, как, чтобы это работало с sh :)) Это имеет несколько приемов, но довольно устойчиво для двух окон.. Сценарий устанавливает отдельные классы для открытых окон хрома (не профили, даже при том, что, именно это я после) Вы могли указать дальнейшие окна также, но они должны быть вручную добавлены путем добавления больше "specificprofile1"
наряду с соответствующей функцией.. Возможно, кто-то мог заставить его иметь больше.. логика!
#!/bin/bash
# chromium-start.sh $1
# e.g. put:
# chrome-start.sh "Profile 1" to .desktop Exec=
# wmctrl -o 1366,0 ; chromium-browser %U --profile-directory=Profile\ 2 & sleep 3; wmctrl -o 0,0
# $1 = Profile folder name
profilename=$1
#2nd Chromium profile
specificprofile1="Profile 1"
echo "starting Chromium"
echo "args: " $1
echo "Profile name: " $profilename
echo "Specific profile: " $specificprofile1
# Just setting Chromium scaling variable, because of course Google Devs don't care about no fractional scaling on linux
scale_var=0.8
# Check if Chromium window with the specified class already exists
# Also allows using icons as "taskbar" switches (clicking icon takes to corresponding Chromium Window)
if wmctrl -l -x | grep "chromium-$profilename"
then
echo "Chromium Window exists, moving focus to it"
wmctrl -x -R chromium-"$profilename"
echo "true"
# Check if 2nd profile $specifiedprofile1 has been started yet or not. The WMCLASS(es) has to have been set correctly...
elif [[ "$specificprofile1" == "$profilename" ]] && [[ ! "`wmctrl -l -x | grep chromium-"$specificprofile1"`" ]]
then
# TODO: Nesting
if [ "$specificprofile1" == "$profilename" ]
then
echo $specificprofile1 "equals" $profilename
fi
echo "#2 Chromium Window for $specificprofile1 does not exist"
# wmctrl moves to specific position of desktop (1366 means moving to the following workspace since my resolution is 1366x768)
# Be careful if using sleep timing, since the command needs to have enough time to execute to have the window in the correct workspace
wmctrl -o 1366,0
chromium-browser --profile-directory="$profilename" --force-device-scale-factor=$scale_var %U &
# https://askubuntu.com/a/626524/654028
# Set's the chromium window which was opened latest to have a custom class, since Chromium doesn't care about the --class= flag...
# It has it's limitations, but should be robust enough for most use... Has not been tested long term.. Something probably could reset the WM_CLASS again
# xprop -id "$(wmctrl -l -x| grep "chromium-browser" | tail -n 1 |awk '{ print $1 }')" -f WM_CLASS 8s -set WM_CLASS "chromium-browser.chromium-$specificprofile1"
# Alternative method for checking if a window with specified class exists
# xprop -id "$(wmctrl -l -x| grep "chromium-$profilename" | tail -n 1 |awk '{ print $1 }')" | grep -o "WM_CLASS(STRING) = ".*"" | grep -o '".*"' | tr -d '"'
# https://stackoverflow.com/a/19441380/5776626
winrep=""
while [[ ! "`echo $winrep | grep -l "Map State: IsViewable"`" ]]
do
winid="$(wmctrl -l -x| grep "chromium-$profilename" | tail -n 1 |awk '{ print $1 }')"
# print $winid
winrep="$(xwininfo -id $winid | grep -o 'Map State: IsViewable')"
# print $winrep
sleep 0.75
xprop -id "$(wmctrl -l -x| grep "chromium-browser" | tail -n 1 |awk '{ print $1 }')" -f WM_CLASS 8s -set WM_CLASS "chromium-browser.chromium-$specificprofile1"
done
# sleep 3
# Move Window directly to workspace (#2 with 1366x768 resolution x = 1366), optionally comment out wmctrl -o 1366,0
# wmctrl -v -i -r $winid -e 0,1366,0,-1,-1
# sleep 5
# Move back to workspace #1
wmctrl -o 0,0
elif ! wmctrl -l -x | grep chromium-"$profilename"
then
echo "#3 Chromium Window $profilename does not exist"
wmctrl -o 0,0
chromium-browser --profile-directory="$profilename" --force-device-scale-factor=$scale_var %U &
# https://askubuntu.com/a/626524/654028
# ....
# sleep 3
winrep=""
while [[ ! "`echo $winrep | grep -l "Map State: IsViewable"`" ]]
do
winid="$(wmctrl -l -x| grep "chromium-$profilename" | tail -n 1 |awk '{ print $1 }')"
# print $winid
winrep="$(xwininfo -id $winid | grep -o 'Map State: IsViewable')"
# print $winrep
sleep 0.75
xprop -id "$(wmctrl -l -x| grep "chromium-browser" | tail -n 1 |awk '{ print $1 }')" -f WM_CLASS 8s -set WM_CLASS "chromium-browser.chromium-$profilename"
done
wmctrl -o 0,0
# xprop -id "$(wmctrl -l -x| grep "chromium-browser" | tail -n 1 |awk '{ print $1 }')" -f WM_CLASS 8s -set WM_CLASS "chromium-browser.chromium-$profilename"
fi
Проблемы:
Печать дает ошибки (предупреждения депрекации..):
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/%{ <-- HERE (.*?)}/ at /usr/bin/print line 528.
Для отладки Вас может использовать следующее для распечатывания ошибок при использовании фактических значков: https://askubuntu.com/a/664272/654028 (# Ручная альтернатива)
awk '/^Exec=/ {sub("^Exec=", ""); gsub(" ?%[cDdFfikmNnUuv]", ""); exit system($0)}' chrome-ws2.desktop
ошибки цикла с условием продолжения, вероятно, из-за интервала цикличного выполнения
Error: no such file "at while function"
xwininfo: error: -id requires argument
xprop: error: Invalid window id format: .
xwininfo: error: -id requires argument
xprop: error: Invalid window id format: .
xwininfo: error: -id requires argument
xprop: error: Invalid window id format: .
Также при нажатии на соответствующий .desktop значок слишком быстро (прежде чем пользовательский класс был установлен?), новое окно будет открыто..
(вполне) Иногда при запуске с обоих Хрома слишком быстро (~ <3 с), класс ранее открытого окна сбрасывается к chromium-browser.chromium-browser.. Затем можно ожидать, что значки подкачают вокруг или другое неожиданное поведение.
Меня вдохновили другие ответы, но я обнаружил, что нам нужно только установить параметры --class
и --user-data-dir
для исполняемого файла Chrome.
Поэтому я написал скрипт, чтобы сделать это автоматически, и если вы хотите попробовать (не волнуйтесь, он не будет выполнять никаких действий, пока вы не подтвердите - если вы не используете --force
), просто запустите:
bash -c "$(curl -fsSL "https://raw.githubusercontent.com/felipecassiors/dotfiles/master/scripts/create_alternative_chrome_shortcut.sh")"
Если вы хотите узнать больше об этом, посмотрите здесь.
Единственное предостережение заключается в том, что, поскольку он использует --user-data-dir
вместо --profile-directory
, новый экземпляр Chrome будет работать как новый. Это необходимо из-за этой ошибки.
В итоге вы получите что-то вроде этого: