编辑 2014-04-19:
为了给我的问题添加一些额外的背景信息,这些是我遵循的原始说明http://ricardofeliciano.me/how-to-create-a-unity-launcher-icon-for-each-chromechromium-profile-in-ubuntu/。在正式发布日期前几周,我让它与 Ubuntu 14.04 LTS 一起工作。在 4 月 17 日更新后,我再也无法让它工作了:
原始帖子:
我在正式发布前几周安装了 Ubuntu 14.04 LTS,并设置了多个 google chromium 配置文件。使用“StartupWMClass”,我设法让每个配置文件在 unity 启动器中拥有一个单独版本的 chromium 图标(相同的图标,在启动器中单独显示)。在 14.04 正式发布后,我更新了所有软件包(包括 chromium),从那时起,我的其他 chromium 配置文件不再在启动器上拥有自己的图标位置,而是与主 chromium 图标组合在一起。
以下是我认为的我的设置的基本内容:
- 在我的 *.desktop 文件下
~/.local/share/applications/
,包含以下行Exec=chromium-browser --user-data-dir=/home/<mydir>/.config/chromium/Profiles/<profile-name> --class=<profile-class-name> %U
StartupWMClass=<profile-class-name>
/usr/share/applications/
我在安装 Chromium 时创建了默认的 Chromium-browser.desktop 文件,其中包含以下几 行Exec=chromium-browser --class=Chromium-browser %U
StartupWMClass=Chromium-browser
在默认安装 .desktop 文件的 Exec= 行中添加--class=Chromium-browser
此技巧,以便每个配置文件(包括默认配置文件)都与启动器上的自己的图标相关联。更新后,我再也无法使它工作了。
我试过:
- 关闭所有 Chromium 窗口,
- 从启动器解锁所有剩余的 Chromium 图标,
- 使用 unity 搜索启动默认的 Chromium Web 浏览器,
- 将出现的图标锁定到启动器
- 使用 unity 搜索启动额外的自定义 Chromium 配置文件
- --> 附加 Chromium 配置文件的窗口与默认 Chromium 配置文件启动的图标相关联。它们使用相同的启动器图标。
我尝试重新启动 compiz、注销甚至重新启动计算机。
对于我可能遗漏的内容有什么提示吗?
ps 有一件事让我感到困惑,那就是我为 Google 日历创建的启动器File -> Create application shortcuts...
按预期工作(使用它自己的不同图标),甚至没有使用--class=<profile>
我认为必要的参数......
答案1
我想到了这个令人憎恶的东西(个人观点...我只是想让它与 sh 一起工作:))它有一些技巧,但对于两个 Windows 来说非常强大。您也可以指定更多窗口,但必须通过添加更多窗口"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。然后您可以预期图标会被交换或出现其他意外行为。