Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

n-abounds

macrumors 6502a
Original poster
Mar 6, 2006
563
0
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.
 

plinden

macrumors 601
Apr 8, 2004
4,029
142
n-abounds said:
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?
 

n-abounds

macrumors 6502a
Original poster
Mar 6, 2006
563
0
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".
 

tag

macrumors 6502a
Apr 29, 2005
918
9
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###
 

n-abounds

macrumors 6502a
Original poster
Mar 6, 2006
563
0
Hmm that last one went a bit over my head, and/or it doesn't seem to work for me. Any other suggestions?
 

plinden

macrumors 601
Apr 8, 2004
4,029
142
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###
 

tag

macrumors 6502a
Apr 29, 2005
918
9
plinden said:
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.
 

n-abounds

macrumors 6502a
Original poster
Mar 6, 2006
563
0
Is there a simpler script if the other person does have "iPod" in the name of their iPod?
 

tag

macrumors 6502a
Apr 29, 2005
918
9
n-abounds said:
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)
 

plinden

macrumors 601
Apr 8, 2004
4,029
142
n-abounds said:
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.
 

janey

macrumors 603
Dec 20, 2002
5,316
0
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 :D

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.