The script below is designed to be run as a folder action. If you're unfamiliar with these, they allow one to monitor a designated folder for any changes to its contents, upon which an AppleScript can be triggered to perform some actions with the items that were added (or removed) from the watched folder.
Whenever one mounts a disk, a mount point is added as a disk item to the /Volumes
folder. Therefore, you can set up a folder action to watch the contents of the /Volumes
folder, and have it trigger an AppleScript whenever a new volume is mounted.
Here's the script that is designed to be triggered:
use sys : application "System Events"
use scripting additions
property text item delimiters : tab
property fp : "~/Desktop/diskinfo.csv"
on adding folder items to Volumes after receiving D
set D to a reference to the sys's disk named (item 1 of D)
set f to a reference to sys's file fp
if not (f exists) then initCSVFile(fp)
set isod to the (current date) as «class isot» as string
get the contents of {isod's text 1 thru 10, ¬
isod's text 12 thru -1, ¬
D's name, ¬
gigabytes(D's capacity), ¬
gigabytes(D's free space)} as text
write the result & linefeed ¬
to (f as alias) ¬
starting at eof ¬
as «class utf8»
end adding folder items to
to gigabytes(bytes)
round bytes / (10 ^ 7)
result / 100
end gigabytes
to initCSVFile(fp)
local fp
set f to make of sys new file with properties {name:fp}
{"Date", "Time", "Volume Name", "Capacity (GB)", "Free Space (GB)"}
write (result as text) & linefeed to (f as alias) as «class utf8»
end initCSVFile
Copy-n-paste this into Script Editor and save it as "New Volume Mounted.scpt"
in the folder ~/Library/Scripts/Folder Action Scripts
, where ~
is your home directory, e.g. /Users/Alex
. If the "Folder Action Scripts"
folder doesn't exist, create it.
If you're happy creating a folder action from here, then do so, and mount a new volume. When the script above is triggered, it adds the current date and time the volume was mounted together with its name, capacity and amount of free space, to the end of the file diskinfo.csv
on your desktop (if the file doesn't exist, the script creates it). This is a CSV (comma-separated value) file, using tabs as delimiters (so, it's actually a TSV). QuickLook can typically display the contents of these files rather nicely:

Folder Action Setup
If you're not familiar with setting up a folder action, then read the section called Attaching a Folder Action Script to a Folder
of the Mac Automation Scripting Guide - Watching Folders
.
However, to save you some time for now, I also created a script that will create the folder action for you:
use sys : application "System Events"
property name : "Volumes"
property path : "/Volumes"
property folder action : a reference to folder action named (my name)
property script : "New Volume Mounted.scpt"
property folder : a reference to Folder Action scripts folder
property file : a reference to the file named (my script) in my folder
set folder actions enabled to true
if not (my file exists) then return open my folder
if my folder action exists then return my folder action's scripts
make new folder action with properties {name:my name, path:my path}
tell my folder action to make new script with properties ¬
{name:my file's name, POSIX path:my file's POSIX path}
set my folder action's enabled to true
set my folder action's scripts's enabled to true
Again, copy-n-paste that into a new document in Script Editor and then run it. Only do so once you've saved the first script to the location I specified, and double check the filename is "New Volume Mounted.scpt"
(you can pick whatever filename you like, but you'll need to make the appropriate change in the script that creates your folder action).
You may need to grant the necessary accessibility privileges for this script to run.
If you run into any problems, let me know.