Run command when (un)plugging (in) Xbox Controller

Hey,
I recently got a USB Xbox 360 Controller and set it up using antimicro and the kernel's xpad driver. Now, I want to start antimicro in the background, when I plug the controller in and stop antimicro when I unplug it.
Is there a more elegant way than running a bash script at startup which periodically checks lsusb's output and acts accordingly?
## command to run when plugged in
/usr/bin/antimicro --no-tray --hidden
## command to run when unplugged
/usr/bin/pkill antimicro
[klemens@arch-pc ~]$ lsusb | grep Xbox
Bus 003 Device 012: ID 045e:028e Microsoft Corp. Xbox360 Controller

OK, I got the reason why not to use the RUN key, but also got confused using a systemd unit. So far, this is it:
[klemens@arch-pc ~]$ cat /etc/udev/rules.d/60-xbox-controller.rules /etc/systemd/system/dev-xbox-{in,out}.device
SUBSYSTEMS=="usb", ATTRS{idVendor}=="045e", ATTRS{idProduct}=="028e", ACTION=="add", SYMLINK+="xbox", ENV{SYSTEMD_WANTS}=="dev-xbox-in.device"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="045e", ATTRS{idProduct}=="028e", ACTION=="remove", SYMLINK-="xbox", ENV{SYSTEMD_WANTS}=="dev-xbox-out.device"
[Unit]
Description=Xbox Controller
[Service]
ExecStart=/usr/bin/antimicro --no-tray --hidden
[Unit]
Description=Xbox Controller
[Service]
ExecStart=/usr/bin/pkill antimicro
Do I have to use service units? (How) can I put this into a single unit with ExecStart and ExecStop? Obviously, this way it's not working...

Similar Messages

  • [solved] hook to run commands when user logs in? (before bash profile)

    Is there any way to run commands when a user logs in but before the bash profile is sourced?
    For example, I have a user account with a home directory on /tmp. When the user logs in, the home directory might not exist so there will be no .bash_profile to source. I want to run a script to create the directory if necessary and copy some files into it. How can that be done?
    I thought of putting something in /etc/profile or /etc/profile.d/, but I would like to run something before the user's shell and environment become active.
    I can use /etc/rc.local to do what I want, but I would prefer a hook to ensure that everything is set right when the user logs in.
    Any ideas?
    *edit*
    Solution
    In my case, I found that I could write my own shell script and set it as a login shell. In the script, I can configure everything I need before launching the interactive shell, then clean up anything after it exits.
    Last edited by Xyne (2011-12-10 19:34:07)

    Thanks, dammannj. PAM could probably do what I need but I think I have found a simpler solution (see original post).

  • Why is my macbook running slow when not plugged into AC power? It runs fine when its plugged in?

    I have a late 2011 macbook 2.7 GHz i7. This wasn't a gradual thing, it just happened all of a sudden. I had upgraded to mountain lion of which I de-fragged my hard-drive thinking it was a hard drive issue, and am now running snow leopard but it hasn't made a difference. Is there like a energy saving option I am unaware of??  Please help, its driving me crazy. Its making my mac literally useless.

    Use Onyx (free) to do a system cleanup (cache cleanup, permissions repair, etc.).

  • My macbook pro running OS X 10.8.3 freezes when I plug an adapter into the displayport, even when nothing is connected to the other (vga) end. Anyone know a solution?

    My macbook pro running OS X 10.8.3 freezes when I plug an adapter into the displayport, even when nothing is connected to the other (vga) end. Anyone know a solution? I have used this adapter with a macbook air and it works flawlessly, but the moment I plug into the minidisplayport the macbook pro freezes with a little spinning color wheel that goes on and on. . .

    Hello there, sarhang27753.
    First thing that would come to mind to resolve the issue would be SMC and PRAM resets. I've linked Knowledge Base articles below:
    SMC
    Intel-based Macs: Resetting the System Management Controller (SMC)
    http://support.apple.com/kb/HT3964
    PRAM
    OS X Mountain Lion: Reset your computer’s PRAM
    http://support.apple.com/kb/PH11243
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro D.

  • How can I disable the Photos app from automatically running when I plug in my iPhone?

    How can I disable the Photos app from automatically running when I plug in my iPhone?
    I have no intention of ever using Photos, in fact, having to abandon Aperture takes me one step close to moving back to Windows, but I digress.
    I just want to NOT have to kill the Photos app every time I plug in my phone.
    Thanks.

    I am still seeing the option Image Capture, like shown in the screenshot that Rysz posted.   But it is another example of the hide-and-seek Apple likes to play with us.
    The option has to be set for each device individually. With the device connected to USB, you have to click the tiny disclosure triangle in the lower left corner of the sidebar to reveal the option.
    I was perfectly happy with the program I paid for (Aperture), and now to maintain the functionality I have to pay for another application (LightRoom) to get the functionality that I paid for in Aperture.
    Aperture 3.6 is working well with Yosemite. I will use it, as long as I have a Mac, that will run Yosemite or a compatible system.
    Have you looked at Capture One?  It looks much more similar to Aperture than Lightroom.

  • My iphone 4S only start whit cable plug in and then show battery very low (with red line end) then try to turn on but show searching in operator name command and not connecting and no work properly and when I plug out it turn off!!! what should I do?

    My iphone 4S only start whit cable plug in and then show battery very low (with red line end) then try to turn on but show searching in operator name command and not connecting and no work properly and when I plug out it turn off!!! what should I do?

    I'm afraid you'll have to get the phone serviced, dropping the phone must have damaged additional parts inside the phone.
    But Apple will not service the phone anymore, opening the phone and replacing the battery should only be done by authorized personal, not by users.
    You'll have to look for a 3rd party repair shop and see if they can fix this, sorry.

  • When I plug my iPhone 4s into my PC, I get an error message that says iTunes needs a newer version of Apple Mobile Device Support. It wants me to uninstall both the AMDS and iTunes and then reinstall iTunes. Has anyone else run into this problem recently?

    When I plug my iPhone 4s into my PC, I get a message that says iTunes needs a newer version of Apple Mobile Device Support. It wants me to uninstall both the AMDS and iTunes and then reinstall iTunes. iTunes won't recognize my phone and so I can't synch it. Has anyone else run into this problem recently and how did you resolve it? Thanks!

    Thank you both. I suppose I should have prefaced my question with the concern that I've read a number of other posts from people who have had a similar issue and when they tried to follow the directions, they ran into a multitude of other problems. As you might imagine, I'm hoping to avoid the creation of new problems as I try to solve this one. Thanks again.

  • When I plug in my iPod nano iTunes asks me to restaure it therefore loosing all my data. Also, there is no tag for Nike Run sync.

    When I plug in my iPod nano iTunes asks me to restaure it therefore loosing all my data. Also, there is no tag for Nike Run sync.
    Can I syncronize my iPod without loosing all its data?. How about syncronizing it to my iPhone?

    Have you tried the steps listed here?
    http://www.consumingexperience.com/2007/11/windows-no-disk-exception-processing. html

  • If i have Time Machine backed up on an external hard drive, do i just plug the drive into another macbook pro and all my stuff is in the new computer?  also, does it matter if the new computer is running Lion when the backed up info came from Snow Leopard

    If i have Time Machine backed up on an external hard drive, do i just plug the drive into another macbook pro and all my stuff is in the new computer?  Also, does it matter if the new computer is running Lion when the backed up info came from Snow Leopard 10.6.8?

    No and Yes
    Don't use TM for this purpose, clone your drive to an external, plug the external into another MBP and reboot from it. Please note that booting a machine that came with Lion may not be possible from a drive with Snow Leopard.

  • When I plug in my iphone 4S to my 64-bit computer a error box comes up in my 64-bit itunes that reads (This iphone cannot be used because the required software is not installed. Run the Itunes installer to remove itunes, than install the 64-bit version of

    When I plug in my iphone 4S to my 64-bit computer a error box comes up in my 64-bit itunes that reads (This iphone cannot be used because the required software is not installed. Run the Itunes installer to remove itunes, than install the 64-bit version of itines.) This just started a few weeks ago. I've done a system restore on my computer, deleated and reinstalled the 64-bit itunes several times, did a registery clean, rebooted. Nothing seems to work it will not pick up my phone.

    Let's try a standalone Apple Mobile Device Support install. It still might not install, but fingers crossed any error messages will give us a better idea of the underlying cause of why it's not installing under normal conditions.
    Download and save a copy of the iTunesSetup.exe (or iTunes64setup.exe) installer file to your hard drive:
    http://www.apple.com/itunes/download/
    Download and install the free trial version of WinRAR:
    http://www.rarlab.com/
    Right-click the iTunesSetup.exe (or iTunes64setup.exe), and select "Extract to iTunesSetup" (or "Extract to iTunes64Setup"). WinRAR will expand the contents of the file into a folder called "iTunesSetup" (or "iTunes64Setup").
    Go into the folder and doubleclick the AppleMobileDeviceSupport.msi (or AppleMobileDeviceSupport64.msi) to do a standalone AMDS install.
    (If it offers you the choice to remove or repair, choose "Remove", and if the uninstall goes through successfully, see if you can reinstall by doubleclicking the AppleMobileDeviceSupport.msi again.)
    Does it install (or uninstall and then reinstall) properly for you? If so, can you get a normal iTunes install to go through properly now?
    If instead you get an error message during the install (or uninstall), let us know what it says. (Precise text, please.)

  • I have downloaded I tune 64bit on my pc ,but when I plug my phone in it says that this version is no good and to download 64 bit version,I'm running windows 7

    Help ,I can't get my phone to be recognized by I tunes,I have downloaded the 64 bit version ,but when I plug my I phone in it says to remove this version and install the 64 bit version ,ahhh it is the 64 bit version ,I am running windows 7

    did you get this sorted I have this problem also

  • HT2801 my disk drive will start up when i plug it in, and runs for about 30 seconds, but wont get recognized in my computer. It used to show up in the finder but that doesnt happen anymore

    my disk drive will start up when i plug it in, and runs for about 30 seconds, but wont get recognized in my computer. It used to show up in the finder but that doesnt happen anymore

    If you go to Disk Utility, can you see the drive on the left hand side? If not, then the drive is dead. You'll have to buy a new drive.
    Also, this forum is "Older Hardware". We specialise in hardware from the 1980s.

  • My mini ipod appears off and not respond to any commands when pressed the buttons to reset, apple logo appeared and then the apple support site and it shuts down. already tried all the steps, but none worked, and when I plug it into my computer it does no

    My mini ipod appears off and not respond to any commands when pressed the buttons to reset, apple logo appeared and then the apple support site and it shuts down. already tried all the steps, but none worked, and when I plug it into my computer it does not appear in the iTunes bar. what do I do?

    If MacKeeper corrupted the Recovery partition then even I underestimated its potential for damage. Garbage "cleaning" apps will cause misery but I have not found that the Recovery partition to have been affected by using MacKeeper or anything like it. I doubt that it did so, but I have learned not to underestimate the potential for such things to result in system corruption.
    Before concluding your Mac has a hardware failure, try booting OS X Internet Recovery by holding command option r on startup (three fingers). That will force your iMac to bypass the Recovery partition altogether, and convey the ability to create a new one.
    An Internet connection will be required (wired or wireless).
    At the Mac OS X Utilities screen, select Disk Utility. Select your startup volume (usually named "Macintosh HD") and click the Repair Disk button. Describe any errors it reports in red. If Disk Utility reports "The volume Macintosh HD appears to be OK" in green then you can be reasonably (though not completely) assured your hard disk is in good working order.
    Assuming the HD remains usable you can then use Disk Utility to erase it. Reinstall OS X, restore your essential software and other files, and don't reinstall the junk.

  • Hello, I have a problem, my macbook pro runs slowly when unplugged but if I plugged it, it runs perfectly.

    Hello, I have a problem, my macbook pro runs slowly when unplugged but if I plugged it, it runs perfectly.

    The battery needs to be replaced, or there is some other hardware problem.

  • Hey, I need to download the OS onto my iPhone 3GS, however, when I plug my phoneinto itunes it does not give me the option to do so, I am currently running 4.2.1. Can anyone help me?

    Hey, I need to download the OS onto my iPhone 3GS, however, when I plug my phoneinto itunes it does not give me the option to do so, I am currently running 4.2.1. Can anyone help me?

    irapidslammz wrote:
    I can not sync it because when I plug it in it says that the apple mobile service has not been started.
    Type " apple mobile device service" into the search bar at the top of this page by Support and read the resulting help article.

Maybe you are looking for