How to automat the selection of usb disk based on size I am trying to automate a process where teachers delete content on memory sticks with different name then put the right content back (same each time) and rename the memory stick to UDISK.

I want to add a formatting of the disk in the process, and because the students keep changing names on the sticks, I can´t use name tags and if the teachers have more than one disk on their Mac I am worried if I use "disk1" for instance I suddenly format the wrong partition. So therefor I am wondering if it is possible to choose the right disk based on size.

I am using this code: sudo diskutil eraseDisk FAT32 UDISK MBRFormat /dev/disk1
This is the script of a similar bulk erase/copy routine I made with the help of klanomath in this related question - Find specific attached disk, not volume, by Applescript which you need to reference to see how the device name is extracted.  

I saved the script as an Automator Service, which I then tied to a non-trivial, in fact very hard to do by accident   Cmd ⌘   Opt ⌥   Shift ⇧   F19    key command in
System Prefs > Keyboard > Shortcuts > Services
so I can manually trigger each operation &amp; not be at risk of it being fired accidentally.

The routine finds the potential target by using the device name of my USB card reader, reducing the risk of formatting at least the wrong disk, though it has no safety measure for the individual SD card &amp; will act on any card in the reader when I hit the key combo.

on run {input, parameters}  
    -- see https://apple.stackexchange.com/questions/207089/find-specific-attached-disk-not-volume-by-applescript/207103#207103 for BSD Disk workings 

    global diskName
    set diskName to "DISK_NAME"
    global BSD_disk
    --using ioreg...
    set BSD_disk to do shell script "ioreg -l | grep -A 10 SD/MMC/MS/MSPRO | awk '/disk/ {gsub(\"\\\"\",\"\"); print $NF}'" 

    if BSD_disk is not "" then
        try
            --FAT 16
            do shell script "diskutil eraseDisk \"MS-DOS FAT16\" " &amp; diskName &amp; " MBRFormat " &amp; BSD_disk
        on error
            try
                --FAT 32 [&gt;2GB cards]
                do shell script "diskutil eraseDisk \"MS-DOS\" " &amp; diskName &amp; " MBRFormat " &amp; BSD_disk
            end try
        end try

        delay 2
        tell application "Finder"
            set x to (POSIX file "/Users/[user]/BatchFolder") as alias
            try
                set dest to (POSIX file "/Volumes/" &amp; diskName as string) as alias
            on error return
            end try
            duplicate every item of x to dest
            delay 1         
            if disk diskName exists then
                eject disk diskName
            end if
            beep
        end tell
    else
        return "no SD Card detected"
    end if

    return input
end run