Go Back   MacRumors Forums > Apple Systems and Services > OS X

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 28, 2006, 07:08 PM   #1
n-abounds
macrumors 6502a
 
Join Date: Mar 2006
Find A Volume Using Terminal

Is there any Terminal command that lets me find a volume with a certain keyword in it (say iPod), even if I don't know the full name of the volume. I'm doing this because I'd like to create a little app that locates another person's iPod, and can then change stuff inside the iPod. And how could I change directories into it?
The "find" command doesn't seem to work.

Last edited by n-abounds; Apr 28, 2006 at 07:16 PM.
n-abounds is offline   0 Reply With Quote
Old Apr 28, 2006, 07:34 PM   #2
plinden
macrumors 68040
 
plinden's Avatar
 
Join Date: Apr 2004
Quote:
Originally Posted by n-abounds
Is there any Terminal command that lets me find a volume with a certain keyword in it (say iPod), even if I don't know the full name of the volume. I'm doing this because I'd like to create a little app that locates another person's iPod, and can then change stuff inside the iPod. And how could I change directories into it?
The "find" command doesn't seem to work.
Where were you running find from? All mounted volumes are under /Volumes. And how many volumes do you have mounted?
plinden is offline   0 Reply With Quote
Old Apr 28, 2006, 07:42 PM   #3
n-abounds
Thread Starter
macrumors 6502a
 
Join Date: Mar 2006
I want to be able to find any volume with, say, "ipod" in the title of the volume. Then I want to change directory into that volume automatically with another command. Possible?

I'm doing this because I want the Terminal command to be able to work on any computer, and still find an "iPod".
n-abounds is offline   0 Reply With Quote
Old Apr 28, 2006, 11:23 PM   #4
tag
macrumors 6502a
 
tag's Avatar
 
Join Date: Apr 2005
Location: PA, US
Well you could approach this different ways, but the thing to remember is, not everyone is going to have the word iPod in the name of their actual iPod, so that can cause a problem. Because of this, just having a script navigate into /Volumes/ and look for the word iPod wouldn't cut it.

To get around that the best way I can think of is by using 'system_profiler' to discover the device.
Here is a quick shell script I wrote which locates the iPod, grabs it's name and path and then goes to it's directory. From there you can add on / modify it as you like to issue any other commands.

This should at least give you an idea of one way it can be done.

Code:
#!/bin/ksh
ipodcheck=`system_profiler SPUSBDataType SPFireWireDataType | grep  "iPod Unit:" -o -m 1 -c`
getvolume=`system_profiler SPUSBDataType SPFireWireDataType | grep  "iPod Unit:" -A 20  | grep "/Volumes/"  | cut -f 2 -d ':'  | cut -c 2-`

if [  "$ipodcheck" = "0" ]
   then print 'No iPod Connected.';exit
   else cd "$getvolume"
fi

#This below part is for testing purposes only
#So now the script is currently in the attached iPods directory
#The following executes 'ls' command to prove it
ls -laTips
#So now that you found and are in the iPods directory you can now add to
#this script so it will cp/mv whatever files you want
###END OF SCRIPT###

Last edited by tag; Apr 28, 2006 at 11:35 PM.
tag is offline   0 Reply With Quote
Old Apr 29, 2006, 10:36 AM   #5
n-abounds
Thread Starter
macrumors 6502a
 
Join Date: Mar 2006
Hmm that last one went a bit over my head, and/or it doesn't seem to work for me. Any other suggestions?
n-abounds is offline   0 Reply With Quote
Old Apr 29, 2006, 11:04 AM   #6
plinden
macrumors 68040
 
plinden's Avatar
 
Join Date: Apr 2004
There are a couple of errors in that script. "print" should be "echo" and "exit" causes Terminal to exit.

But this only works if the iPod is configured for disk use. If not, it is automatically unmounted after update, and even though the ipodcheck result is "1" (i.e. the Mac recognises that the iPod is still connected) there is no Volume.

You need to check for "$ipodcheck" = "0" OR "$getvolume" = ""

Try this:
Code:
#!/bin/ksh
ipodcheck=`system_profiler SPUSBDataType SPFireWireDataType | grep  "iPod Unit:" -o -m 1 -c`
getvolume=`system_profiler SPUSBDataType SPFireWireDataType | grep  "iPod Unit:" -A 20  | grep "/Volumes/"  | cut -f 2 -d ':'  | cut -c 2-`

if [  "$ipodcheck" = "0" ] || [ "$getvolume" == "" ]
    then echo 'No iPod Connected.';
    else
        #So now that you found and are in the iPods directory you can now add to
        #this script so it will cp/mv whatever files you want
        cd "$getvolume";
        ls;
fi

###END OF SCRIPT###
plinden is offline   0 Reply With Quote
Old Apr 29, 2006, 02:41 PM   #7
tag
macrumors 6502a
 
tag's Avatar
 
Join Date: Apr 2005
Location: PA, US
Quote:
Originally Posted by plinden
There are a couple of errors in that script. "print" should be "echo" and "exit" causes Terminal to exit.

But this only works if the iPod is configured for disk use. If not, it is automatically unmounted after update, and even though the ipodcheck result is "1" (i.e. the Mac recognises that the iPod is still connected) there is no Volume.

You need to check for "$ipodcheck" = "0" OR "$getvolume" = ""

Try this:
Ok thats odd, the exit didn't cause a Terminal exit for me, just a script exit, not sure why (do you know why that did for you and not me? Just wondering, I mean the only reason I threw it in there was so it wouldn't execute the ls command if the check failed). Anyways I totally didn't think about my iPod being set up for disk use, that really does change things.

So somehow you would need to have the script manually mount the iPod first (is that possible if it's not set up for disk use? I don't have my iPod with me right now to play around with it. I guess you'd have to find the mount points somehow?). Or state in the apps instructions that you have to enable disk mode for the app to work.
tag is offline   0 Reply With Quote
Old Apr 29, 2006, 03:29 PM   #8
n-abounds
Thread Starter
macrumors 6502a
 
Join Date: Mar 2006
Is there a simpler script if the other person does have "iPod" in the name of their iPod?
n-abounds is offline   0 Reply With Quote
Old Apr 29, 2006, 04:21 PM   #9
tag
macrumors 6502a
 
tag's Avatar
 
Join Date: Apr 2005
Location: PA, US
Quote:
Originally Posted by n-abounds
Is there a simpler script if the other person does have "iPod" in the name of their iPod?
Well yeah you could do this really simply, though I have to say if you want this to work with just a simple command line argument I don't think it's possible without creating at least one temporary file to store information so your best bet would be a script. Though maybe plinden can correct me if I'm wrong on that.

So simpler as you want it.. with this following script which will find any variation of iPod (ipod IPOD ipOd etc.. excluding dot files) in /Volumes and then go to the directory.

Like this for example..

Code:
#!/bin/ksh
ipod=`ls /Volumes/ | grep -i iPod`

if [ -n "$ipod" ];then
  cd /Volumes/"$ipod";
  ls;
 else echo 'Cannot find the iPod! OMG what now?! Buh bye.'
fi
NOTE: Some flaws can be found with this route..

a)the users iPod must have the word iPod in the name

b)if another drive is mounted with the word iPod in the name, conflicts arise (i.e. backup iPod music cd, etc) (though this could be remedied by checking to see if the directory has write access, though you would still have problems with CD/DVD-RW's and external drives)

c)this wont work with non mounted ipods not in disk mode (of course neither does the prior script deal with this problem either)
tag is offline   0 Reply With Quote
Old Apr 29, 2006, 08:36 PM   #10
plinden
macrumors 68040
 
plinden's Avatar
 
Join Date: Apr 2004
Quote:
Originally Posted by n-abounds
Is there a simpler script if the other person does have "iPod" in the name of their iPod?
Maybe, but the idea of the original script is good in that it's the simplest way of doing it effectively. Anything that makes the assumption of iPod in the name isn't going to be that much simpler and won't be as effective.

The system_profiler check isn't that complicated. To learn about system_profiler, you can read its man pages (in Terminal type "man system_profiler").

If you just want to list the names of all mounted Volumes containing "iPod" you can do this :
Code:
ls /Volumes | grep iPod
Or you can use this to get information on the mounted volume:
Code:
disktool -l | grep iPod
But I don't know a way of mounting an iPod if it's not in disk mode.
plinden is offline   0 Reply With Quote
Old Apr 30, 2006, 06:04 AM   #11
janey
macrumors 603
 
janey's Avatar
 
Join Date: Dec 2002
Location: sunny los angeles
/Volumes on my iBook has a habit of showing multiple copies of the same volume..
Code:
df | grep iPod
works just fine for me

Just as a heads up, neither of my iPods have 'iPod' in the name...so...that's a particularly bad way of looking for iPods.
__________________
iPad | 15" MacBook Pro | black (iPhone 3GS|MacBook) | Mac mini server
moof!

janey is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > OS X

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
How to find out program serial number through Terminal? kathrynk MacBook Pro 3 Nov 26, 2013 05:50 PM
Can I have cmd + volume keys (f11, f12) changing iTunes volume? madsylar OS X 5 Oct 12, 2013 11:03 AM
IR Apple Remote, iTunes Volume instead of System volume Dr Kevorkian94 Mac Peripherals 1 Jul 13, 2013 01:22 PM
You cannot install Safari on this volume. This volume already has a newer version of abidkhan135 Mac Applications and Mac App Store 2 Jul 10, 2013 08:30 AM
How to find the System Sound Volume? zaxonus iPhone/iPad Programming 1 Jul 9, 2012 04:40 PM

Forum Jump

All times are GMT -5. The time now is 12:59 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC