Last active
July 24, 2017 19:24
-
-
Save uupaa/9d854bc95423c6f93b1837a62357bb55 to your computer and use it in GitHub Desktop.
get external SD card ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const execa = require("execa"); | |
const to_json = require("xmljson").to_json; | |
const EXTERNAL_DIR = "/Volumes"; // mac | |
function getExternalSDCardID(readyCallback, errorCallback) { | |
const params = ["list", "-plist", "external", "physical"]; | |
// diskutil list -plist external physical | |
execa("diskutil", [...params]).then(result => { | |
to_json(result.stdout, (err, root) => { | |
//console.log(JSON.stringify(root, null, 2)); | |
if (err) { console.error(err.message); errorCallback(err); return; } | |
if (root.plist.dict.array["2"]) { | |
readyCallback( root.plist.dict.array["2"].string ); | |
} else { | |
errorCallback(new Error("SD_CARD NOT FOUND")); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment