ubuntu 14.04 + gnome 3.10 + gnome-shell restart
有没有办法让gnome-shell在每次启动时运行shell脚本?
(比如在Alt + F2然后r ,而不是登录)
注意:如果您认为它与启动列表有关,则不是:执行Alt + F2然后r并告诉我启动列表中的应用是否已启动:它们不是(至少不在我的设置中)。
不幸的是,通过shell脚本它还没有工作:
#!/bin/bash gnome-shell --replace sleep 10 ## reset screen config xrandr --output HDMI1 --mode 1920x1080 --pos 0x0 --rotate normal --output VIRTUAL1 --off --output DP1 --off --output eDP1 --off --output VGA1 --off ## reset keyboard setxkbmap fr
xrandr命令在启动时按预期工作
如果我输入终端sh rgnome.sh,gnome会重新启动,但下一个命令似乎没有执行(如果我关闭终端它会杀死gnome); 我不熟悉shell脚本,所以我可能会做一些明显错误的事情
您可以在路径中创建可用的shell脚本,也可以将其命名为r.sh.
该脚本应该调用gnome-shell –replace命令,然后调用用于修复显示配置的命令。
在运行这些命令之前,您可能需要等待几秒钟才能等待替换成功。
编辑:
脚本可能是这样的:
#!/bin/bash gnome-shell --replace sleep 2 fix-your-display-commands
您的shell脚本不起作用,因为xrandr
命令正在等待gnome-shell --restart
退出。 由于在gnome运行时不会发生这种情况,因此不会执行xrandr
命令。 您需要告诉脚本在后台运行它,这样后续命令也将运行:
#!/usr/bin/env bash ## Start gnome-shell in the background. That's what the & does gnome-shell --replace & sleep 10 xrandr --output HDMI1 --mode 1920x1080 --pos 0x0 --rotate normal --output VIRTUAL1 --off --output DP1 --off --output eDP1 --off --output VGA1 --off
现在,将脚本保存在全局$PATH
中的某个位置,例如/usr/bin/rgnome.sh
,使其成为可执行文件( sudo chmod 755 /usr/bin/rgnome.sh
)然后运行Alt + F2和r ,使用Alt + F2和rgnome.sh
。
评论后我决定我应该完成一个答案:
这可能有助于您了解如何使用.bashrc和.bash_profile
.bash_profile vs .bashrc
如果你没有这个文件,请不要担心,如果你创建它,shell应该以你的家中保存.bash_profile的用户登录时使用它。
只有当您的用户将bash作为默认shell时,上面列出的建议才有效。 因此,您可以考虑更深层次,如下所示。
如果您对为所有用户运行脚本感兴趣,您应该考虑编辑/ etc / profile文件。
我想你可以通过help.ubuntu.com在本节中找到一些答案