How to exclude the main or boot drive from list

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
Simon Knight
Posts: 407
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

How to exclude the main or boot drive from list

Post by Simon Knight » Thu Jul 19, 2018 3:57 pm

Hello,

I am in the process of writing a utility that locates movie files across all connected hard drives. I am using the volumes command to create a list of volumes (drives) and on my apple mac and at present it returns the following:

Macintosh HD
home
net
LUMIX
MediaDisc_20120512
LR_BackupB
Lightroom Library
MobileBackups
Overspill
MBP Timemachine
Media_Disk

I wish to exclude the main drive which on my machine is named "Macintosh HD" from the list and wonder if there is an elegant method of identifying it in code. For instance is it safe to assume that the first item in the list is the main boot volume?
best wishes
Skids

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5525
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to exclude the main or boot drive from list

Post by dunbarx » Thu Jul 19, 2018 4:31 pm

Hi.

Is the "main" volume always the first line in the list?

Also, I am not sure, but there must be a function that returns the current machine volume. Something like getting one level "up" from the long name of a stack.

Craig Newman

Simon Knight
Posts: 407
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: How to exclude the main or boot drive from list

Post by Simon Knight » Thu Jul 19, 2018 4:51 pm

Well Home Folder returns Users/AccountName which is one below the drive name but I have not been able to get the full path (yet). Also I am not sure why the volumes command includes "home" and "net" as I have been unable to get them to resolve into absolute paths.

I think its to hot for all this thinking!

best wishes
Simon K
best wishes
Skids

Klaus
Posts: 10325
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to exclude the main or boot drive from list

Post by Klaus » Thu Jul 19, 2018 4:53 pm

Hi Simon,

since Windows always shows the drive letter, this is only important on macOS.
One can maybe check the existence of the DESKTOP folder or something like that.
This e.g. works:

Code: Select all

on mouseUp
   put line 1 of the volumes into tV
   put specialfolderpath("desktop") into tD
   put "/Volumes/" & tV & "/" & tD into tFolder
   answer there is a folder tFolder
end mouseUp
Give me TRUE, maybe that is a starting point for you.


Best

Klaus

Simon Knight
Posts: 407
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: How to exclude the main or boot drive from list

Post by Simon Knight » Thu Jul 19, 2018 5:59 pm

Hi Klaus,

Yes that works well - thanks.

However, the operation of the Volumes command seems odd to me. Items 2 and 3 on the list are "home" and "net". Neither of these are volumes but I suspect that they are special in some way. For instance they are included in list the items in the root folder/volume i.e. "Macintosh HD" but they are not visible in the Finder. I suspect that they get resolved to a logical name depending on the active account set at log in.

The result is that it seems quite complicated to obtain a list of media that are available for searching.

This is what I have come up with based on the code in your post:

Code: Select all

on mouseUp

   Put the volumes into tList
   -- seek the name of the main hard drive
   repeat for each line tLine in tList
      if IsMainDrive (tLine) then
         put tLine into tMainDrive
         exit repeat
      end if
   end repeat
   
   repeat for each line tLine in tList
      if tLine = tMainDrive then next repeat  -- ignore this data line, we know what it is.
      put "/Volumes/" & tLine into tPath
      if there is a folder tPath then
         put tLine & cr after tDataDrives  -- excluding the main drive
      end if
   end repeat
   
   -- now clean up
   put the home folder & cr before tDataDrives  -- add the users drive to list
   delete the last char of tDataDrives
   answer tDataDrives
end mouseUp

Function IsMainDrive pVolume
   put specialfolderpath("desktop") into tDeskTopPath
   put "/Volumes/" & pVolume & "/" & tDeskTopPath into tFolder
   if there is a folder tFolder then
      return true
   end if
   return false
end IsMainDrive


It lists mounted disk images as well as other data disks. No doubt it can be improved as it seems like hard work to get a list of data storage devices.

best wishes
Simon K
best wishes
Skids

Klaus
Posts: 10325
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to exclude the main or boot drive from list

Post by Klaus » Thu Jul 19, 2018 6:14 pm

Hi Simon,

glad I could help!

BTW: Mr. Boole is our friend!

Code: Select all

Function IsMainDrive pVolume
   put specialfolderpath("desktop") into tDeskTopPath
   put "/Volumes/" & pVolume & "/" & tDeskTopPath into tFolder
   return (there is a folder tFolder)
end IsMainDrive
:-)


Best

Klaus

Simon Knight
Posts: 407
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: How to exclude the main or boot drive from list

Post by Simon Knight » Thu Jul 19, 2018 9:39 pm

Re Mr. Boole,

Its a fair cop! :oops:
best wishes
Skids

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4609
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to exclude the main or boot drive from list

Post by jacque » Fri Jul 20, 2018 8:02 pm

There may be drives that have a system installed but are not the current startup drive, so they would have a Desktop folder too. It might be safer to test to see if the volume has the path to the current stack. That's likely to be the boot drive, but it does assume the other mounted volumes aren't a clone of the current one.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

karmacomposer
Posts: 256
Joined: Wed Apr 27, 2011 2:12 pm

Re: How to exclude the main or boot drive from list

Post by karmacomposer » Fri Jul 20, 2018 8:07 pm

Not to stomp over the OP in this thread, but my problem is similar:

Why does this not give me a file path:

Code: Select all

global varLastBlock
      put "/PDAForm" & varLastBlock & ".pdf" into tPDFPath
It gives me what I want but on two lines. Where is the return in this such that it goes to the next line?

I need it on one line.

Thanks and sorry for posting here.

Mike

ClipArtGuy
Posts: 177
Joined: Wed Aug 19, 2015 4:29 pm

Re: How to exclude the main or boot drive from list

Post by ClipArtGuy » Fri Jul 20, 2018 8:48 pm

karmacomposer wrote:
Fri Jul 20, 2018 8:07 pm
Where is the return in this such that it goes to the next line?
Mike
Is it possible that your variable contains a carriage return? try this

Code: Select all

global varLastBlock
      put "/PDAForm" & varLastBlock & ".pdf" into tPDFPath
     replace return with empty in tPDFpath

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4609
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to exclude the main or boot drive from list

Post by jacque » Fri Jul 20, 2018 9:05 pm

I wondered why /net and /home showed up in the Volumes on OS X (there are others too.) It turns out these are a sort of virtual volume that OS X maintains. They aren't really mount points, they are more like containers. Anyway, that led me to a terminal command which led me to experiment.

This seems to return mounted volumes, omitting the current startup disk:

Code: Select all

function getVols
  put shell("df -H") into tVols
  filter tVols with "*/Volumes/*"
  get replaceText(tVols,".*Volumes\/",empty)
  return it
end getVols
Edit: This probably only works on OS X and Linux.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Simon Knight
Posts: 407
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: How to exclude the main or boot drive from list

Post by Simon Knight » Fri Jul 20, 2018 11:05 pm

Hi Jacque,

Great method of getting the volumes without having to conduct any tests. Anyone using this or the volumes command should probably ignore the volume mobilebackups as this seems to be for OSX's use only and hangs my application if it attempts to search it. I read somewhere that some of these special folders/volumes store compressed files. Also and although I have not checked, I would guess that the permissions are restrictive.

best wishes
Simon K.
best wishes
Skids

Post Reply

Return to “Talking LiveCode”