我使用 i3 窗口管理器,每天的远程工作我都想运行一个负责设置我的显示器的脚本。周二,我在现场工作,然后我想运行另一个脚本。我可能可以使用 bash 条件来解决我的问题,但我宁愿利用这个机会了解有关 systemd 的更多信息,而不仅仅是启动/停止/重新启动/启用/禁用 :D
这是我的脚本(从终端启动时工作正常)
#!/bin/sh
xrandr --output eDP-1 --off --output HDMI-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal --output DP-1 --off --output DP-2 --off --output DP-3 --off --output DP-4 --off
这是我的设备(仅当通过 systemctl --user start home_screen_setup.service 从终端启动时才有效)
[Unit]
Description=Monitors setup when I work from home
After=graphical-session.target
BindsTo=graphical-session.target
PartOf=graphical-session.target
Requisite=graphical-session.target
ConditionEnvironment=DISPLAY
ConditionEnvironment=XAUTHORITY
[Service]
Type=oneshot
ExecStart=/home/userX/.screenlayout/home_setup.sh
[Install]
WantedBy=graphical-session.target
这是我的计时器
[Unit]
Description=Setup my screen configuration on every day except Tuesday
[Timer]
#OnBootSec=15seconds
OnCalendar=Mon,Wed,Thu,Fri
[Install]
WantedBy=timers.target
一些状态输出:
userX@HP-ProBook-450:~$ systemctl --user status home_screen_setup.service
○ home_screen_setup.service - Disables laptop screen when I work from home
Loaded: loaded (/home/userX/.config/systemd/user/home_screen_setup.service; enabled; vendor preset: enabled)
Active: inactive (dead)
TriggeredBy: ● home_screen_setup.timer
userX@HP-ProBook-450:~$ systemctl --user status home_screen_setup.timer
● home_screen_setup.timer - Setup my screen configuration on every day except Tuesday
Loaded: loaded (/home/userX/.config/systemd/user/home_screen_setup.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Sun 2024-03-03 12:00:22 CET; 1min 4s ago
Trigger: Mon 2024-03-04 00:00:00 CET; 11h left
Triggers: ● home_screen_setup.service
mar 03 12:00:22 HP-ProBook-450 systemd[2306]: Started Setup my screen configuration on every day except Tuesday.
我究竟做错了什么?