本文目录导读:

- 方案一:使用 f.lux(推荐,最简单)
- 方案二:使用 Redshift(Linux 系统)
- 方案三:自定义定时脚本
- 方案四:macOS 专用脚本
- 方案五:Windows 系统(PowerShell 脚本)
- 推荐使用方式
- 注意事项
我来帮你创建一个调整显示器色温的脚本,主要有两种方案:
使用 f.lux(推荐,最简单)
#!/bin/bash # 安装 f.lux(如果是 macOS) # brew install --cask flux # 或者使用命令行版本 # 对于 Linux 用户 sudo apt-get install redshift
使用 Redshift(Linux 系统)
#!/bin/bash # install.sh - 安装脚本 sudo apt-get update sudo apt-get install redshift redshift-gtk # 创建配置文件 cat > ~/.config/redshift.conf << EOF [redshift] temp-day=5500 temp-night=3500 transition=1 brightness-day=1.0 brightness-night=0.7 location-provider=manual [manual] lat=39.9 lon=116.4 EOF
自定义定时脚本
#!/bin/bash
# 自动调整色温脚本
# 保存为: adjust_color_temp.sh
# 配置
DEFAULT_TEMP=6500 # 白天色温
NIGHT_TEMP=3500 # 夜间色温
# 获取当前小时(24小时制)
CURRENT_HOUR=$(date +%H)
# 根据时间调整色温
adjust_color_temperature() {
local hour=$1
# 6:00-18:00 使用正常色温
if [ $hour -ge 6 ] && [ $hour -lt 18 ]; then
echo "白天模式:色温 $DEFAULT_TEMP"
# 这里调用系统命令调整色温
# 具体命令取决于你的系统
# 18:00-6:00 使用暖色调
else
echo "夜间模式:色温 $NIGHT_TEMP"
# 调整到暖色调
fi
}
# 执行调整
adjust_color_temperature $CURRENT_HOUR
macOS 专用脚本
#!/bin/bash
# macOS 原生方式调整显示器色温
# 需要先安装 cliclick 或使用系统偏好设置
# 创建定时任务
cat << 'EOF' > ~/Library/LaunchAgents/com.user.colortemp.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.colortemp</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/redshift</string>
<string>-l</string>
<string>39.9:116.4</string>
<string>-t</string>
<string>5500:3500</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
EOF
# 加载定时任务
launchctl load ~/Library/LaunchAgents/com.user.colortemp.plist
Windows 系统(PowerShell 脚本)
# save as: adjust_color_temp.ps1
# 需要在管理员模式下运行
# 设置任务计划
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-Command `"& {`n
\$hour = (Get-Date).Hour
if (\$hour -ge 6 -and \$hour -lt 18) {
Write-Host 'Daytime mode: Normal temperature'
# 这里调用 Windows API 或第三方工具调整色温
} else {
Write-Host 'Night mode: Warm temperature'
}
}`""
$trigger = @(
@{ScheduleId='Daily'; StartBoundary='06:00'},
@{ScheduleId='Daily'; StartBoundary='18:00'}
)
Register-ScheduledTask -TaskName "ColorTempAdjuster" -Action $action -Trigger $trigger
推荐使用方式
-
最简单方案:安装 f.lux 或 Night Shift(macOS/iOS 内置)
-
Linux 用户:使用 Redshift
# 安装后自动运行 systemctl --user enable redshift systemctl --user start redshift
-
自定义方案:结合 cron 定时任务
# 添加到 crontab # 每30分钟检查一次 */30 * * * * /path/to/adjust_color_temp.sh
注意事项
- 不同的操作系统和显示器可能需要不同的调整方法
- 某些显示器支持 DDC/CI 协议,可以通过命令行控制
- 建议先在白天和夜间分别测试色温值
- 过度降低色温可能影响颜色准确性,建议合理设置
你需要哪种操作系统的具体实现?我可以提供更详细的代码。