|
|
#1 |
|
Prospect
Join Date: Apr 2010
Posts: 35
|
How do you detect if something is connected to a USB drive?
Hi,
I'm using Mac 10.7.5. Per my other posts, I'm trying to write a bash (or other suitable) shell script to conditionally launch an application. The launch is contingent upon whether there is the apporpriate device connected to one of the USB drives. How can I detect what is connected through a script? Thanks, - Dave |
|
|
|
|
|
#2 |
|
League Commissioner
Join Date: Jan 2002
Posts: 7,963
|
Your description is a little fuzzy. I don't know of other devices that can be connected to an already-connected USB drive, as USB doesn't offer "daisy-chain" capabilities, as far as I know.
So, can I say that you want to write a script that will detect that a USB mass storage device is already connected, and also when a USB device is added to your computer? Are you only interested in mass storage, or are there other USB devices that you want to know about? Keep in mind that a Mac laptop might already have as many as 6 USB devices on the USB bus, before you have anything attached externally. So, what, exactly, do you consider an "appropriate device"? |
|
|
|
|
|
#4 |
|
Hall of Famer
Join Date: Dec 2007
Posts: 3,642
|
Likewise, there's the Do Something When add-on for System Preferences which can easily be set up to launch an application when a volume mounts.
http://www.azarhi.com/Projects/DSW/index.php It hasn't been updated in a while, but it still works fine under 10.7, just needing System Preferences to run in 32-bit mode. |
|
|
|
|
|
#5 |
|
Hall of Famer
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,946
|
It still works in Mountain Lion. When you double-click it in System Preferences, a drop-down sheet like the one below drops. It simply restarts System Preferences in 32-bit mode and after a pause, you get the DSW window.
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3 |
|
|
|
|
|
#6 |
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 31,941
|
I'd tend to just try doing whatever operation it does and then deal with the error condition if there is no USB device etc.
__________________
hayne.net/macosx.html |
|
|
|
|
|
#7 |
|
Prospect
Join Date: Apr 2010
Posts: 35
|
Hi,
DeltaMac, I have a device called MagicJack that alows me to make phone calls from my computer. When you plug the device into your USB port, you can then launch an application that lets you make phone calls. I was looking for a scriptable way to launch this application at system startup. I found out that when the device gets plugged in, there is something at "/Volumes/magicJack." NaOH, I tried "Do Somewhen When" and set up a rule (see the attached file), but unfortunately, my app didn't launch when I rebooted my computer. THanks for the ideas, - Dave |
|
|
|
|
|
#8 |
|
Hall of Famer
Join Date: Dec 2007
Posts: 3,642
|
Since I don't have the device or application for testing, make certain you have the volume and application names perfectly correct. It looks like you do, but it's worth confirming on your end.
|
|
|
|
|
|
#9 |
|
Hall of Famer
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,946
|
Why not just set the app to start at login in System Preferences > Accounts > Login Items?
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3 |
|
|
|
|
|
#10 |
|
Prospect
Join Date: Apr 2010
Posts: 35
|
The reason I don't have the app always start at login is because sometimes the device is not connected and so launching the app would be useless since it wouldn't do anything (both the app have to be launched and teh device connected in order to make phone calls)
|
|
|
|
|
|
#11 |
|
Hall of Famer
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,946
|
Then post #3 above is your answer -- Lingon is a simple program for setting up launchd conditions. When you plug in the device or when it's discovered at login, it will launch the program.
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3 |
|
|
|
|
|
#12 |
|
Prospect
Join Date: Apr 2010
Posts: 35
|
Does Lingon make a distinction between system startup and user login? I created a Lingon "My Agent" using this script
Code:
[ -d /Volumes/magicJack ] && /Users/davea/.magicJack/Softphone/magicJack.app/Contents/MacOS/magicJack || echo "File does not exist" > /Users/davea/magic.out Thanks, - Dave |
|
|
|
|
|
#13 |
|
Hall of Famer
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,946
|
Which of the boxes in the figure below did you check? Note that there is one for login.
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3 |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|