AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1200476
Accepted
AFoeee
AFoeee
Asked: 2020-01-04 11:22:06 +0800 CST2020-01-04 11:22:06 +0800 CST 2020-01-04 11:22:06 +0800 CST

如何在连接 Wacom 数位板后立即运行配置脚本(通过 USB)?

  • 772

我在 Ubuntu 18.04 ( Kernel: 4.15.0-72-generic ) 下使用 Wacom 绘图板。

不幸的是,我无法使用系统设置对其进行配置,因为它无法正确识别。

配置通过xsetwacom工作,但不是持久的。只要我重新启动计算机或重新插入设备,就会加载默认设置。


我认为最简单的解决方案是在平板电脑被识别为 USB 设备后立即运行配置脚本。

根据我的理解,要做到这一点需要两个步骤:

  1. 创建 udev 规则

    我创建了一个/etc/udev/rules.d/99-config_wacom_intuos.rules包含以下内容的文件:

    # "idVendor" and "idProduct" were derived from the output of the lsusb command.
    ACTION=="add" \
    , SUBSYSTEM=="input" \
    , KERNEL=="mouse*" \
    , ATTRS{idVendor}=="1234" \
    , ATTRS{idProduct}=="5678" \
    , RUN+="/bin/sh -c '/usr/local/bin/config_wacom_intuos.sh >> /var/log/custom_logs/config_wacom_intuos.log 2>&1'"
    

    该文件具有以下权限:

    -rw-r--r-- 1 root root    ...
    

    (这本词典/var/log/custom_logs也是我创作的。)

  2. 创建配置脚本

    我创建了一个/usr/local/bin/config_wacom_intuos.sh包含以下内容的文件:

    #!/bin/bash
    #coding:utf8
    
    # These were the missing statements as suggested by the answer.
    #export DISPLAY=:1
    #export XAUTHORITY=/run/user/1000/gdm/Xauthority
    
    echo "`date '+%Y-%m-%dT%H:%M:%S'`, ShellPID $$, start"
    
    sleep 1
    
    if xsetwacom --list devices | grep -q "Wacom Intuos BT"
    then
        main_screen="HEAD-0"
        bezier_args="0 20 80 100"
        positioning_mode="Absolute"
        raw_sample_lvl="9"
        suppress_lvl="10"
    
        # Maps the graphics tablet to the area of a specified screen (for multiple-screen environments).
        xsetwacom set "Wacom Intuos BT S Pen stylus" MapToOutput "$main_screen"
        xsetwacom set "Wacom Intuos BT S Pen eraser" MapToOutput "$main_screen"
        xsetwacom set "Wacom Intuos BT S Pen cursor" MapToOutput "$main_screen"
    
        # Changes the pressure sensitivity.
        xsetwacom set "Wacom Intuos BT S Pen stylus" PressureCurve "$bezier_args"
        xsetwacom set "Wacom Intuos BT S Pen eraser" PressureCurve "$bezier_args"
    
        # Smoothes drawn lines by reducing any quivering.
        xsetwacom set "Wacom Intuos BT S Pen stylus" RawSample "$raw_sample_lvl"
        xsetwacom set "Wacom Intuos BT S Pen stylus" Suppress "$suppress_lvl"
        xsetwacom set "Wacom Intuos BT S Pen eraser" RawSample "$raw_sample_lvl"
        xsetwacom set "Wacom Intuos BT S Pen eraser" Suppress "$suppress_lvl"
        xsetwacom set "Wacom Intuos BT S Pen cursor" RawSample "$raw_sample_lvl"
        xsetwacom set "Wacom Intuos BT S Pen cursor" Suppress "$suppress_lvl"
    
        # Specifies the positioning mode ("Absolute" / "Relative")
        xsetwacom set "Wacom Intuos BT S Pen stylus" Mode "$positioning_mode"
        xsetwacom set "Wacom Intuos BT S Pen eraser" Mode "$positioning_mode"
        xsetwacom set "Wacom Intuos BT S Pen cursor" Mode "$positioning_mode"
    
        # Assigns actions to the tablet buttons.
        xsetwacom set "Wacom Intuos BT S Pad pad" Button 1 "key +ctrl z -ctrl"
        xsetwacom set "Wacom Intuos BT S Pad pad" Button 2 "key +ctrl +shift z -ctrl -shift"
        xsetwacom set "Wacom Intuos BT S Pad pad" Button 3 "key 0xffab"
        xsetwacom set "Wacom Intuos BT S Pad pad" Button 8 "key 0xffad"
    
    else
        echo "NO 'WACOM INTUOS BT' DEVICES FOUND."
    fi
    
    echo "`date '+%Y-%m-%dT%H:%M:%S'`, ShellPID $$, end"
    echo -e "---\n"
    
    exit 0
    

    该文件具有以下权限:

    -rwxr-xr-x 1 root root    ...
    

当我从终端手动执行脚本时,它工作得很好。

当我插入设备时它也会执行。不幸的是,这似乎没有任何效果。

此外,该脚本在插入设备后会连续执行多次。
我认为这种行为是由于 udev 规则而发生的,该规则的限制性不够。

谁能告诉我,我做错了什么?

automation bash wacom udev 18.04
  • 1 1 个回答
  • 1586 Views

1 个回答

  • Voted
  1. Best Answer
    Tim Schumacher
    2020-01-06T10:23:45+08:002020-01-06T10:23:45+08:00

    X 服务器工具通常只影响您当前的会话(这就是您每次都必须设置它们的原因)。

    由于您在未附加到任何 X 会话的 shell 中运行该脚本,因此该工具不知道应该为哪个 X 会话更改这些设置(或者更准确地说,它不知道 X会话甚至存在)。

    您可以手动将您的 shell 连接到您当前的 X 会话,但有时该解决方案可能有点脆弱。

    您需要在脚本中添加两个变量导出,一个 forDISPLAY和XAUTHORITY. 这些用于识别和访问正确的 X 会话。env您可以通过在以普通用户身份登录时运行来获取适当的值。

    就我而言,输出如下所示(省略标记的部分[...]):

    $ env
    [...]
    XAUTHORITY=/home/tim/.Xauthority
    [...]
    DISPLAY=:0.0
    [...]
    

    对于这些值,我需要通过以下几行扩展脚本:

    export DISPLAY=:0.0
    export XAUTHORITY=/home/tim/.Xauthority
    

    现在,即使您是 root 用户,该脚本也应该可以工作。

    udev 配置本身似乎很好。

    • 1

相关问题

  • 从 bash 迁移到 zsh [关闭]

  • bashrc 还是 bash_profile?

  • Mac OS X Automator 的替代品?

  • 备份 bash 脚本未压缩其 tarball

  • 我如何参与 Ubuntu 的测试和 QA?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve