Go Back   The macosxhints Forums > OS X Help Requests > UNIX - Newcomers



Reply
 
Thread Tools Rate Thread Display Modes
Old 01-24-2013, 01:29 PM   #1
laredotornado
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
laredotornado is offline   Reply With Quote
Old 01-24-2013, 02:01 PM   #2
DeltaMac
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"?
DeltaMac is offline   Reply With Quote
Old 01-24-2013, 03:32 PM   #3
NovaScotian
Hall of Famer
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,946
You can use launchd (via Lingon 3) to run a script whenever a particular drive is connected -- that's how my backups work.
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3
NovaScotian is offline   Reply With Quote
Old 01-24-2013, 03:37 PM   #4
NaOH
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.
NaOH is offline   Reply With Quote
Old 01-24-2013, 05:02 PM   #5
NovaScotian
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.
Attached Thumbnails
Click image for larger version

Name:	screenshot_01.png
Views:	31
Size:	34.2 KB
ID:	4624  
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3
NovaScotian is offline   Reply With Quote
Old 01-24-2013, 08:45 PM   #6
hayne
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
hayne is online now   Reply With Quote
Old 01-27-2013, 04:36 PM   #7
laredotornado
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
Attached Thumbnails
Click image for larger version

Name:	dsw.png
Views:	36
Size:	63.3 KB
ID:	4626  
laredotornado is offline   Reply With Quote
Old 01-27-2013, 04:40 PM   #8
NaOH
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.
NaOH is offline   Reply With Quote
Old 01-27-2013, 04:46 PM   #9
NovaScotian
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
NovaScotian is offline   Reply With Quote
Old 01-27-2013, 07:51 PM   #10
laredotornado
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)
laredotornado is offline   Reply With Quote
Old 01-28-2013, 09:11 AM   #11
NovaScotian
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
NovaScotian is offline   Reply With Quote
Old 01-28-2013, 09:33 AM   #12
laredotornado
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
(complete description is attached) but the script isn't executing properly (the app doesn't launch when I'm log in). However, when I run that script at a terminal, everythign runs fine. I think Lingon may be executing it at system startup and I would prefer it execute it at user login. Any way I can control that?

Thanks, - Dave
Attached Thumbnails
Click image for larger version

Name:	lingon.jpg
Views:	38
Size:	65.6 KB
ID:	4628  
laredotornado is offline   Reply With Quote
Old 01-28-2013, 09:43 AM   #13
NovaScotian
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.
Attached Thumbnails
Click image for larger version

Name:	Lingon.png
Views:	43
Size:	70.8 KB
ID:	4629  
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3
NovaScotian is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 11:39 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.