设置 Ubuntu 启动时的音量

发布于 2024-07-11 10:41:25 字数 401 浏览 7 评论 0原文

Ubuntu 启动/登录声音可能非常大,但我确实喜欢它。 我编写了一个使用 amixer 将音量设置为 25% 的脚本。 这是我喜欢的音量,但当我使用电视输出或耳机时,我必须调高音量。 我似乎无法在登录声音播放之前运行脚本。 我尝试过 cron @reboot,并将符号链接放入 /etc/rc3.d/ 和我的 .bash_profile 脚本中的脚本。 只有第三种方法实际上可以正确设置音量,但是在登录后会播放声音。

理想情况下,我希望在晚上注销时或在 ubuntu 登录屏幕显示之前运行该脚本。

以下是设置音量的命令:

`/usr/bin/amixer -c 0 sset Master,0 25% > /dev/null`

欢迎尝试其他方法的建议。

The Ubuntu startup/login sound can be very loud, but I do like having it. I wrote a script that uses amixer to set the volume to 25%. This is the level I like to have it at, but when I use TV out or headphones I have to turn up the volume. I cannot seem to get the script to run before the login sound plays. I have tried a cron @reboot, and putting a symlink to the script in /etc/rc3.d/, and in my .bash_profile script. Only the 3rd method actually sets the volume correctly, but after the login sound plays.

Ideally I want to have the script run when I am logging out for the night, or just before the ubuntu login screen displays.

Here is the command to set the volume:

`/usr/bin/amixer -c 0 sset Master,0 25% > /dev/null`

Suggestions for other methods to try are appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

像你 2024-07-18 10:41:26

创建单元配置并启用它以启动。

假设ALSA和systemd(Ubuntu使用14以后的systemd版本)

/etc/systemd/system/alsavolume.service

在这里创建一个单元文件。 您可以调整命令来运行 /usr/bin/amixer sset PCM -- 97%。 记住不要使用引号(否则 systemd 会将整个内容解释为命令)。

[Unit]
Description="Set volume level."
After=sound.target

[Service]
Type=simple
ExecStart=/usr/bin/amixer sset PCM -- 97%

[Install]
WantedBy=multi-user.target

启用它(这意味着创建一个到 /etc/systemd/system/multi-user.target.wants 的符号链接以在启动时运行,但以下命令会为您处理它。)

  1. 重新加载守护进程

    systemctl 守护进程重载

  2. 启用服务

    systemctl启用alsavolume.service

    您可以添加参数--now以立即运行该单元。

Create a unit configuration and enable it for startup.

Assuming ALSA and systemd (Ubuntu uses systemd version after 14 onwards)

/etc/systemd/system/alsavolume.service

Create a unit file here. You can adjust the command to run /usr/bin/amixer sset PCM -- 97%. Remember not to use quotations (otherwise systemd will interpret the whole thing as a command).

[Unit]
Description="Set volume level."
After=sound.target

[Service]
Type=simple
ExecStart=/usr/bin/amixer sset PCM -- 97%

[Install]
WantedBy=multi-user.target

Enable it (this means creating a symbolic link to /etc/systemd/system/multi-user.target.wants to run at startup, but the following commands take care of it for you.)

  1. Reload daemons

    systemctl daemon-reload

  2. Enable service

    systemctl enable alsavolume.service

    You can add the parameter --now to run the unit immediately.

星光不落少年眉 2024-07-18 10:41:26

我之前使用过这个方法来实现这一点,但是是在Arch Linux上。 现在,我不太熟悉 Ubuntu 使用的 init 系统,但我想你可以尝试将其适应 Ubuntu。

I've used this method to achieve that before, but on Arch Linux. Now, I'm not too familiar with the init system Ubuntu uses, but I guess you could try adapting this to Ubuntu.

眼趣 2024-07-18 10:41:26

您可以做的是编写一个脚本来在关闭计算机时降低音量。
像这样:

#!/bin/sh

amixer -- sset Master playback -40dB

exit 1 

然后在关机时运行此脚本。

What you can do is to write a script to lower down your volume when you shut down your computer.
Something like this:

#!/bin/sh

amixer -- sset Master playback -40dB

exit 1 

then run this script at shutdown.

哆兒滾 2024-07-18 10:41:25

您可能想尝试将该行添加到 /etc/rc.local 中,但这可能还不够快,因为 rc.local 将在 gdm 之后调用。

另请注意,Ubuntu 上的默认运行级别是 2,而不是 3。 您在 rc3.d 中的链接可能不起作用,只是因为您没有使用运行级别 3。默认运行级别由 /etc/event.d/rc-default 设置

You might want to try adding that line to your like to /etc/rc.local This may not be soon enough though, since rc.local will be called after gdm.

Also note, the default runlevel on Ubuntu is 2, not 3. Your link in rc3.d probably didn't work simply because you where not using runlevel 3. The default runlevel is setup by /etc/event.d/rc-default

岁月蹉跎了容颜 2024-07-18 10:41:25

我相信Ubuntu的启动脚本已经包含了“alsactl恢复”。 您应该能够在卷已设置为 25% 的情况下运行“alsactl store”,并影响所有以后的重新启动。

I believe that Ubuntu's startup scripts already include an "alsactl restore". You should be able to run "alsactl store" with the volume already set to 25% and affect all future reboots.

清晰传感 2024-07-18 10:41:25

啊,是的,但是它们在关闭时是否还包含一个“alsactl store”?

Ahh, yes, but do they also contain an "alsactl store" on shutdown?

最终幸福 2024-07-18 10:41:25

罗布,

我正在尝试解决同样的问题。 我在上面的“amixer”行中做了很多研究,了解运行级别、/etc/rc#.d 文件夹和 update-rc.d 命令。 它并不完美。 它在重新启动期间仍然没有按照我希望的方式运行,但它是一个开始。

欢迎提出改进建议。

而且,这是我的代码......

sudo echo "#!/bin/bash" > /etc/init.d/lowvol.sh

sudo echo "/usr/bin/amixer -c 0 sset Master,0 35% > /dev/null" >> /etc/init.d/lowvol.sh

sudo chmod +x /etc/init.d/lowvol.sh

sudo chown root:root /etc/init.d/lowvol.sh

sudo update-rc.d lowvol.sh stop 20 0 6 。

Rob,

I am trying to solve the same issue. I took you "amixer" line above and did alot of poking around learning about runlevels, the /etc/rc#.d folders and the update-rc.d command. It's not perfect. It still doesn't run during a restart the way I would want it to, but its a start.

Suggestions to improve it would would be welcome.

And, here is my code below.....

sudo echo "#!/bin/bash" > /etc/init.d/lowvol.sh

sudo echo "/usr/bin/amixer -c 0 sset Master,0 35% > /dev/null" >> /etc/init.d/lowvol.sh

sudo chmod +x /etc/init.d/lowvol.sh

sudo chown root:root /etc/init.d/lowvol.sh

sudo update-rc.d lowvol.sh stop 20 0 6 .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文