Detecting SD Memory cards

  1. 7 months ago

    Without using a third party library is there a way to detect the insertion/removal of an SD memory card ? I have searched these forums but it seems to be a topic which has not been tackled. The app is to run on Mac OS only, no windows or linux in this case. Any advice/help most appreciated.

  2. Dave S

    1 Feb 2019 San Diego, California USA

    They should be considered a "drive", and there are methods to detect mounting and ejecting drives.... I'd have to search my archives to find it... but that is what you should try.

  3. This is an interesting theme. Made a test with Terminal's command "Diskutil".

    You need to know what drive names are mounted and check them with "Diskutil info "VolumeName"

    In the code below, the name "Mac SD Card" says nothing about, as this is the Volume name, but you could look for the line "protocol" in the thread.result string, if it is "Secure Digital", it is for sure an SD card installed
    (for example, the "Macintosh HD" protocol result is "PCI-Express").

    Me, had installed a SD card permamently, so the information about this one is the following:

    NameOfComputer:~ MyUsername$ diskutil info "Mac SD Card"
       Device Identifier:        disk3s1
       Device Node:              /dev/disk3s1
      ...
       Volume Name:              Mac SD Card
       Mounted:                  Yes
       Mount Point:              /Volumes/Mac SD Card
    
       Partition Type:           Apple_HFS
        ...
       OS Can Be Installed:      No
       Media Type:                 Generic
       Protocol:                      Secure Digital
       SMART Status:             Not Supported
      
       Disk Size:                513.0 GB (512996932608 Bytes) (exactly 1001947134 512-Byte-Units)
       Device Block Size:        512 Bytes
       ...
       Device Location:          Internal
       Removable Media:          Removable
       Media Removal:            Software-Activated

    Device location is not forced to be "Internal", as one can also use an SD card inserted into the SD card slot of a printer.

  4. @Marek P — You can use NSWorkspace in Cocoa to detect new volumes or ejections, but it will require a fair amount of declares

or Sign Up to reply!