Score:1

automatically run script when inserted USB

mc flag

I have a file .xscreensaver & the code/script as below

sudo cp -R .xscreensaver /home/amg/

How can I make the code/script autorun when I insert a USB?

ChanganAuto avatar
us flag
Making anything autorun from external media is a very bad idea. That's why even in Windows such feature was disabled many years ago.
guiverc avatar
cn flag
You've provided no OS/product/release details; as having scripts auto-run can vary on desktop/release being used as many DE/setups disable it by default for security reasons. eg. I have Ubuntu setups here that don't even `mount` a USB by default on insertion, so expecting them to autorun before a `mount` is performed makes no sense.
mchid avatar
bo flag
[See this answer](https://askubuntu.com/a/642524/167115). Just understand that **doing so can cause security issues if you ever insert a USB that contains malicious code.** Also, in addition to the instructions, you may need to go to your file manager preferences and disable the option to "ask before running" to get rid of the popup prompt.
mchid avatar
bo flag
In the comments, they mention that on Linux Mint, the option is under "file management preferences" (whatever that is) but I believe they may be talking about how nautilus has an option to "ask before running" or something similar. Please let us know if the answer doesn't work and why.
mchid avatar
bo flag
There's also [this similar question](https://askubuntu.com/q/284224/167115). In this scenario, the command or the code is executed when a certain USB device is inserted. The code that is executed is not on the device but you tell Ubuntu to execute the code automatically when a specified device is inserted.
mchid avatar
bo flag
So you would need to specify the vendor id and the product id of your specific USB device (you can obtain that when the device is plugged in and you run `lsusb`). Then, when you insert the particular USB device, Ubuntu will recognize it and this will trigger a script on your Ubuntu computer to run. Just ignore the "out" or unplug portion of the answer.
uz flag
Jos
@mchid I think that the second question you link to ("this similar question") is more in line with OP's needs than the first, so I'll vote to close as duplicate ot that one. It has an excellent answer.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.