我想要两个完全不同的实例Chromium,每个都有自己的图标,因此:
- 有两个任务栏按钮,并且...
- ...窗口切换器中的两个条目(Ubuntu 18,GNOME)
- 它们可以通过图标/颜色轻松区分
- 我可以在这两个实例之间Alt+ ,也可以在实例内的窗口之间+ (上面的键)TabAlt`Tab
我怎样才能做到这一点?
我考虑过的解决方案:
- 不同的配置文件- 不满足要求,因为所有配置文件中的所有 Chromium 窗口都集中在同一个任务栏按钮和窗口切换器条目下。
- 安装 Chrome Beta 和 Chrome Dev。它们不完全是 Chromium,我更喜欢开源的 Chrome。
- 安装 Chromium beta/dev。这可能有效,但 PPA 似乎是由一名随机开发人员维护的,他与 Google 没有任何关系。如果版本受到损害,安全隐患将非常严重。此外,我更喜欢 Chromium 的稳定性,而测试版/开发版往往不太稳定。
- 我已将 /usr/lib/chromium-browser 复制到 /usr/lib/chromium-browser-2,并创建
~/.local/share/applications/chromium-browser-2.desktop
指向它的本地快捷方式,带有单独的图标。这在 Dash 中显示了一个单独的图标,但在启动它时,它打开了我现有的 Chromium 配置文件,并且窗口仍然与现有的 Chromium 窗口混在一起。看起来可执行文件在某种程度上肯定有所不同?
答案1
.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
行中,由于这个 Chromium 错误。
结果
答案2
我受到了其他答案的启发,但我发现我们只需要为 Chrome 的可执行文件设置--class
和--user-data-dir
选项。
所以我编写了一个脚本来自动完成这个操作,如果你想尝试(不用担心,在你确认之前它不会执行任何操作——除非你使用--force
),只需运行:
bash -c "$(curl -fsSL "https://raw.githubusercontent.com/felipecassiors/dotfiles/master/scripts/create_alternative_chrome_shortcut.sh")"
如果你想了解更多信息,请查看这里。
唯一需要注意的是,由于它使用--user-data-dir
而不是--profile-directory
,新的 Chrome 实例将像一个全新的实例一样运行。这是因为这个错误。
最后,你会得到如下结果:
答案3
我知道的最简单的方法是使用更多工具 -> 创建快捷方式。从那里它将创建一个 .desktop 条目,您可以自定义图标,并且可以chrome://apps
修改设置,例如以窗口形式打开。
答案4
当谈到 Chromium 时,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
while 循环出错,可能是因为循环间隔
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 图标时(在设置自定义类之前?),将会打开一个新窗口。
(相当)有时当从 Chromium 启动得太快(~<3 秒)时,先前打开的窗口的类会被重置为 chromium-browser.chromium-browser。然后您可以预期图标会被交换或出现其他意外行为。