I attached code and configuration files to this post. It's quite a bunch
of little puzzle pieces, but I like it that way because it's in fact not
restricted to a use in the squeezeslave context, but more of a generic
USB event handler triggering any kind of actions.
Feel free to comment or change anything you would do different (C or
Bash code, error handling, permissions, paths, etc.).
INSTALLATION INSTRUCTIONS
1. The content of the folder Application Support goes to
/Library/Application Support.
2. The binary usb-detect goes to /usr/local/bin.
3. Modify the user permissions, product ID, vendor ID, and audio device
ID according to your situation.
In the zip, we have the following components:
BIN/USB-DETECT
A compiled executable which detects (dis)connects of a specified USB
device. It runs on my OS X 10.6 Intel Mac mini. (No idea whether the
binary is universal or downward compatible; did I mention that I don't
know much about Mac programming? :-) It accepts the two decimal integer
parameters vendor ID and product ID, which for my USB DAC looks like
Code:
--------------------
>/usr/local/sbin/usbdetect 3468 12
--------------------
The vendor ID 3468 (hex 0x0d8c) and product ID 12 (hex 0x000c) of my
USB DAC I could tell from the following command:
Code:
--------------------
>system_profiler SPUSBDataType
[...]
C-Media USB Headphone Set :
Product ID: 0x000c
Vendor ID: 0x0d8c (C-MEDIA ELECTRONICS INC.)
[...]
--------------------
SRC/MAIN.C
Source code for detection of USB devices. It has to be linked with the
frameworks CoreFoundation and IOKit. It's based upon the Apple code on
http://developer.apple.com/library/mac/#samplecode/USBPrivateDataSample/Introduction/Intro.html
APPLICATION SUPPORT/USB-DETECT/USB-DETECT.PLIST
A sample launchd service parameterization file. It runs an instance of
the usb-detect binary for my USB DAC.
APPLICATION SUPPORT/USB-DETECT/VENDOR-3468-PRODUCT-12/DEVICE-ADDED
This script restarts the squeezeslave service by changing to folder
/Library/Application Support/squeezeslave and running the script
Code:
--------------------
/Library/Application Support/squeezeslave>./restart 2
--------------------
The 2 stands for the audio device ID squeezeslave associates to the USB
DAC and can be infered from
Code:
--------------------
>squeezeslave -L
* 1: (Core Audio) Built-in Output (1/10)
2: (Core Audio) C-Media USB Headphone Set (2/29)
--------------------
APPLICATION SUPPORT/USB-DETECT/VENDOR-3468-PRODUCT-12/DEVICE-REMOVED
Same as device-added. The reason for this is that the restart action
will effectively shut down the service if the audio device is not
available, see below.
APPLICATION SUPPORT/SQUEEZESLAVE/SQUEEZESLAVE
A wrapper script for the squeeslave binary. Example:
Code:
--------------------
/Library/Application Support/squeezeslave>./squeezeslave 2
--------------------
checks whether the audio device 2 is up and launches an instance of
squeezeslave for that device on mac 00:00:00:00:00:02 if the device is
up.
APPLICATION SUPPORT/SQUEEZESLAVE/START
Accepts a command line parameter for the audio device ID and launches a
service running a squeezeslave instance dedicated to this output:
Code:
--------------------
/Library/Application Support/squeezeslave>./start 2
--------------------
The parameter 2 tells the script to use squeezeslave.2.plist as the
service definition file, see below. If the service doesn't come up for
some reason (in my case, the main reason is when the USB device is not
connected), it shuts down the service right away.
APPLICATION SUPPORT/SQUEEZESLAVE/STOP
The antagonist of Application Support/squeezeslave/start.
Code:
--------------------
/Library/Application Support/squeezeslave>./stop 2
--------------------
APPLICATION SUPPORT/SQUEEZESLAVE/RESTART
Combines stop with a subsequent start:
Code:
--------------------
/Library/Application Support/squeezeslave>./restart 2
--------------------
APPLICATION SUPPORT/SQUEEZESLAVE/SQUEESLAVE.[12].PLIST
Service definition files for audio device 1 and 2, respectively.
+-------------------------------------------------------------------+
|Filename: usb-detect.zip |
|Download: http://forums.slimdevices.com/attachment.php?attachmentid=11024|
+-------------------------------------------------------------------+
--
nikipore
------------------------------------------------------------------------
nikipore's Profile: http://forums.slimdevices.com/member.php?userid=41997
View this thread: http://forums.slimdevices.com/showthread.php?t=83994
_______________________________________________
discuss mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/discuss