I’ve reformatted a CORSAIR volume to FAT32 using the following command.
do shell script "diskutil eraseVolume \"MS-DOS FAT32\" PZV /Volumes/CORSAIR"
I now want to rename the volume from PZV to PZV&USBNUMBER
where USBNUMBER is equal to “10001” or “10002” or “10003” or …
THe outcome would be that the volume will then name PZV10001 or PZV10002 or PZV…
The USBNUMBER is a sequential number which will always be five digit long. In looking through the forum I’ve found this link http://macscripter.net/viewtopic.php?id=21597. Unfortunately it is now archived.
Does someone knows where I could find some information on what I am attempting to do?
It has always been a problem writing scripts here due to lack of description. Please describe as if no one has any idea what your talking about, assuming nothing.
From what I can gather it looks like you want to rename multiple volumes due to the sequential numbering yet you say
So I am left to assume you will have multiple volumes to rename. So here’s what I think you want:
property VolumeNumber : 10001-- This stores a counter that will change each time you rename a drive
on open ThisVolume
set ThisVolume to ThisVolume as item
tell application "Finder" to set name of ThisVolume to "PZV" & VolumeNumber
set VolumeNumber to VolumeNumber + 1--this adds 1 each time a new volume is names
end open
on run
set thecommand to text returned of (display dialog "Reset Volume Number" default answer "10001" as string)
set VolumeNumber to thecommand
end run
What the above is when saved as an “application” is a “droplet”. That means drag your volume on top of the droplet and let go of the mouse button. It will then rename your volume as you wanted. The next volume dropped will have a number one more than the one before it.
The reason for making a droplet is so the “run” function allows you to change the starting number to what ever you like, or reset to the original. If you double click the droplet a dialog box opens that allows you to reset the counter.
However, why not use the shell script to name them properly upon reformatting?
property VolumeNumber : 10001
on open ThisVolume
--split the script at the usb number point
set BeginningScript to "diskutil eraseVolume " & (ASCII character 34) & "MS-DOS FAT32" & (ASCII character 34) & " PZV"
--end of shell script after volume number
set endscript to " /Volumes/CORSAIR"
--rebuild shell script with dynamic number.
set VolumeNameShellScript to (BeginningScript & VolumeNumber & endscript) as string
do shell script VolumeNameShellScript
--Everytime you drop a new volume the number will increase by 1
set VolumeNumber to VolumeNumber + 1
end open
--double click application to reset the volume number start point
on run
set thecommand to text returned of (display dialog "Reset Volume Number" default answer "10001" as string)
set VolumeNumber to thecommand
end run
Right from the beginning I wanted to use the DO SHELL SCRIPT command and I was having problems with back slashes [b][/b].
In your script you made me learn to use the ASCII code instead (ASCII character 34).
The tip about using the BeginningScript and the endscript to feed information for the DO SHELL SCRIPT command is excellent
In my final solution I’ve introduced the variable CurrentVolumeName that I would set to “CORSAIR” at this time. In doing so I will not bel limited to only CORSAIR volume in the future. The operator executing the script will be then be able to provide the name of the mounted disk prior at execution time.
No need for me to change the script because using another volume type.