This is a nice feature to have in gnirehtet. I wonder if it's easy to implement in scrcpy.
Something like:
./gnirehtet autorun
?
:wink:
exactly, but for scrcpy
Ah, sorry, I read the question too fast :) I added the _feature request_ label.
If it's just for 1 device, you can do something like:
while :; do adb wait-for-device && scrcpy; done
(except that it will rerun _scrcpy_ as soon as you close the window)
Cool, thanks
udev rule is another option in Linux.
@npes87184 Yes :+1:
Here is an exemple (for gnirehtet): https://github.com/Genymobile/gnirehtet/issues/49#issuecomment-343525703
I have written a udev rule and systemd.service to achieve this feature.
Below is detail
/etc/udev/rules.d/99-scrcpy.rules as:ACTION=="add" \
, SUBSYSTEM=="usb" \
, ENV{DEVTYPE}=="usb_device" \
, ATTRS{idVendor}=="XXXX" \
, ATTRS{idProduct}=="XXXX" \
, TAG+="systemd" \
, ENV{SYSTEMD_WANTS}="scrcpy.service"
where you should specify idVendor and idProduct for your device (simply use lsusb).
sudo udevadm control --reload-rules to reload udev.rule/etc/systemd/system/scrcpy.service as:[Unit]
Description=Start scrcpy when correct usb device is plugged
[Service]
Type=simple
Environment=XAUTHORITY=/home/<username>/.Xauthority
Environment=DISPLAY=:0
ExecStartPre=/bin/sleep 3
ExecStart=/usr/local/bin/scrcpy
[Install]
WantedBy=multi-user.target
where you should specify your username to get correct cookie. also, you should setup DISPLAY environment variable based on your environment.
systemctl daemon-reload to reload systemd serviceThat's all!
RUN+= in udev.rule?it will show Dec 25 21:52:25 npes87184 systemd-udevd[471]: seq 22149 '/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3.1' is taking a long time in syslog. In additional, other udev event will be delayed.
ENV{DEVTYPE}=="usb_device" in udev.rule?to prevent triggering more than once.
Hi,
I just wrote and published a tiny tool to execute a command whenever a device is adb-connected: autoadb.
autoadb scrcpy -s {}
_({} is replaced by the serial of the devices)_
Here are binaries (I did not create a release yet, and the Windows version is not tested):
Feedbacks welcome.
Great! It works as expected. However I also have a local fork with libusb keyboard support that requires usb id like 18d1:4ee7. Is it possible to let autoadb provide that info?
Is it possible to let
autoadbprovide that info?
The adb daemon does not provide this info on device connection:
printf '0012host:track-devices' | nc localhost 5037
So you have to resolve it manually from the serial :confused:
hmm, perhaps rust ecosystem has some usb related stuff which might help?
Most helpful comment
Ah, sorry, I read the question too fast :) I added the _feature request_ label.
If it's just for 1 device, you can do something like:
(except that it will rerun _scrcpy_ as soon as you close the window)