Any cross-platform methods to detect a mounted SD card? I would love to know how programs like Etcher and the official SD Card formatter detect only (micro/mini/regular) SD cards…
My hope is to create a somewhat idiot-proof formatting function in my program that won’t format anything but a micro-SD card.
Search with your title in this Forum: question already asked.
But not completely answered. I’ll keep digging. Thanks!
I spent some times on google and all I found are threads that talks about
not detecting an SD card
Yeah, I did a lot of searching too. I can’t find the “secret” way that Etcher and SD Card formatter are able to detect only SD cards!
diskutil list on the Mac command line. You’ll see that an SD card is listed as “
internal, physical”. An external hard drive is listed as “
external, physical”. Physical obviously means they’re an actual physical drive, as opposed to a disk image or partition. Etcher likely skips /dev/disk0, the internal drive, and then proceeds to look at the rest of the drives that are marked as physical, and parses the output from those. When I run Etcher, it shows me both the 1TB external HD and the SD card.
Here’s what diskutil list looks like on my Mac and also the Etcher dialog. Hope that helps.
Thank you, Gavin!
I was clearly mistaken. I should have tested this myself before claiming that those programs “figured it out”.
I tried SDCard Formatter on Windows and it also falsely detected an external USB stick and an external hardware device (that shows up as an external drive)
I don’t know that Xojo’s FolderItem object gives enough information to determine internal/external and physical. It looks like MBS has a plugin, or maybe I can try parse shell commands to do it.
So, the reason why nobody gave a definitive explanation is because none exists yet !
Looks like running a shell and parsing DiskUtil’s output on MacOS should be easy enough. DiskPart on Windows is strange command, though, without a simple command line. It uses it’s own interpreter and you have to “select” disks and volumes interactively. Yuck.
I can see why MBS created their own functions. It looks tricky.
Looks like SetupDiGetDeviceRegistryProperty might be useful in Windows. I’ll have to bone up on my Declares!
Reading your text above made my brain working fast (so fast then the ventilators were running )
The question was: Are there still SD Cards in Apple hardware ?
MacBook Pro 16": nope.
An HP laptop ($1200): I am unable to check, the internet is wrong for me now (works for one web site and not for others
yes there are, even my 2017 iMac has one, never used it. but it has one
There were two ways in which I tried to solve this with my old “Backup To Go”, as the macOS (used) to know and provide different icons for different devices.
- Using NSURL, I was able to detect the device path “dev/disk3” of the volume, then I tried to look up how it was connected to the Mac, the built-in SD Card reader, identified as “SD Card reader” on the internal USB bus. I tried a couple of methods to get this information, I seem to recall that using “System Profiler” was very very very slow. I also recall that there was another API I tried to get this information that was fast. But it was rejected from the App Store, because it used “Private” API.
- The second and most hairbrained idea was to use NSAPI to load the icon for SD cards, then to get the icon from the volume and compare the Ptrs, it worked, except when the user had a custom icon.
So I gave up.
Removing the SD Card reader from Apple’s “Professional” laptops was a bizarre move from my opinion, as when you’re mobile and want to download photos from your camera, the SD card reader was perfect, it didn’t drain the camera’s battery to download Photos, and didn’t require a photographer to have to carry around an extra device/cable to do so.
All my cameras use an SD card, yet they have different cables with different connectors and thus require me to carry an extra “dongle” to either connect the various cables or to read an SD card. The great thing about Dongles is that they’re designed to last a year or so, which means I have to replace them after a while. I’ve stopped buying expensive ones ($20~$40 a time), and now just buy the cheap $3 ones from the local stationary store, when they fail.
My error: I forget some words here: in on sale computers
Otherwise, yes, in my 2014 (yes 5 years in one week/manufactured 2014-11-24) have an SD Card built in (and I used it until my Lenovo crashed: bad hardware/company). Only two USB port: was not enough.
Never used since.
BTW: the HP Laptop I had in mind does not have one too (a actual laptop on sale).
I was thinking at the Target audience of the software.
Thinking sales ? My stupid idea.
Doesn’t really matter if the computer has a built-in card reader or it’s an external USB to SD card reader, I just want to make a utility that allows users to format a micro-SD card correctly for our device (needs to be FAT32), with the lowest chance of accidentally formatting the wrong drive.
I figure the best way (after I’ve checked as much as I can using Declares and so on) is to get the user to remove and re-insert the card. It’d be easy enough to detect that the most likely card was removed and re-inserted and that would confirm that it’s the one to format.
Emile… I would check before you post. All iMacs currently on sale (on the official Apple Website) have SD card slots
it seems it was removed in 2016 from the MBP laptops, but NOT the desktop computer (well the iMac at least)
Using it as final check is a good idea, but beware.
- The maOS periodically mounts and unmounts volumes all the time. There is an option to mount without displaying in Finder, so the user doesn’t see these volumes, but applications do.
- There might be another circumstance whereby a volume is mounted at the same time as a user inserts an SD Card, i.e. the macOS or even a 3rd party application might mount a hidden volume to do an update.
The macOS does know what is an SD card and what isn’t, heck it even knows if one is mounted when connecting a camera. My advice to you is to figure out exactly HOW the macOS knows this, especially as you are attempting to format a volume, which is a destructive action, and any accidental data loss because of this will will be your fault, as far as the user is concerned.
A quick Google and one trick I see is people using the ImageCapture framework to see if the device shows up there or not. It’s probably still not fool proof. I just tested this and a SD card from my camera shows up, but another SD card I have and use for exchanging files. does not.
system_profiler SPStorageDataType -detailLevel full
Will reveal lots of information about the drives connected to the Mac, add “-xml” to the end to get a machine readable XML dictionary.
system_profiler SPUSBDataType Will reveal everything connected to the USB bus, this includes SD card readers.
The information from here shows that the SD Card is marked as “STORAGE DEVICE” and “Removable Media: Yes” while a USB drive is not. This value is also obtainable from NSURL properties. I never truly understood the different between NSURLVolumeIsRemovableKey and NSURLVolumeIsEjectableKey, maybe this will finally be clear.
Hey Sam, if you have a moment, could you show an example of how to write a Declare for MacOS that uses NSURL? I did a search but couldn’t seem to find an example of that kind of Declare, and I’m a bit lost on the MacOS stuff.