How to exclude the main or boot drive from list
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 845
- Joined: Wed Nov 04, 2009 11:41 am
- Location: Gunthorpe, North Lincs, UK
How to exclude the main or boot drive from list
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?
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
Skids
-
- VIP Livecode Opensource Backer
- Posts: 9578
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to exclude the main or boot drive from list
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
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
-
- Posts: 845
- Joined: Wed Nov 04, 2009 11:41 am
- Location: Gunthorpe, North Lincs, UK
Re: How to exclude the main or boot drive from list
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
I think its to hot for all this thinking!
best wishes
Simon K
best wishes
Skids
Skids
Re: How to exclude the main or boot drive from list
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:
Give me TRUE, maybe that is a starting point for you.
Best
Klaus
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
Best
Klaus
-
- Posts: 845
- Joined: Wed Nov 04, 2009 11:41 am
- Location: Gunthorpe, North Lincs, UK
Re: How to exclude the main or boot drive from list
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:
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
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
Skids
Re: How to exclude the main or boot drive from list
Hi Simon,
glad I could help!
BTW: Mr. Boole is our friend!
Best
Klaus
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
-
- Posts: 845
- Joined: Wed Nov 04, 2009 11:41 am
- Location: Gunthorpe, North Lincs, UK
-
- VIP Livecode Opensource Backer
- Posts: 7214
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: How to exclude the main or boot drive from list
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
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 361
- Joined: Wed Apr 27, 2011 2:12 pm
Re: How to exclude the main or boot drive from list
Not to stomp over the OP in this thread, but my problem is similar:
Why does this not give me a file path:
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
Why does this not give me a file path:
Code: Select all
global varLastBlock
put "/PDAForm" & varLastBlock & ".pdf" into tPDFPath
I need it on one line.
Thanks and sorry for posting here.
Mike
-
- Posts: 253
- Joined: Wed Aug 19, 2015 4:29 pm
Re: How to exclude the main or boot drive from list
Is it possible that your variable contains a carriage return? try thiskarmacomposer wrote: ↑Fri Jul 20, 2018 8:07 pmWhere is the return in this such that it goes to the next line?
Mike
Code: Select all
global varLastBlock
put "/PDAForm" & varLastBlock & ".pdf" into tPDFPath
replace return with empty in tPDFpath
-
- VIP Livecode Opensource Backer
- Posts: 7214
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: How to exclude the main or boot drive from list
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:
Edit: This probably only works on OS X and Linux.
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
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 845
- Joined: Wed Nov 04, 2009 11:41 am
- Location: Gunthorpe, North Lincs, UK
Re: How to exclude the main or boot drive from list
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.
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
Skids