Search code examples
applescriptapplescript-objc

How to rename startup disk?


I'm running the codes below to rename the startup disk, to perform some procedures my question is if after performing these procedures I can rename the disk to its name "Original"

that is, I have a disk named "Big Sur" and running the codes below it is renamed to: "Apple HD" but soon after performing the other tasks it returns the name to: Big Sur I tried to store the name in a variable but this does not work since the startup disk is renamed at runtime to "Apple HD".

tell application "Finder" to set diskName to name of startup disk
set newName to "Apple HD"

tell application "Finder" 
to set newName to diskName
end tell

Solution

  • -- save original name into the variable, to restore it later
    tell application "Finder" to set diskName to name of startup disk
    
    -- rename startup disk
    tell application "Finder" to set name of startup disk to "Apple HD"
    
    -- perform some procedures here
    
    -- rename startup disk back to original name
    tell application "Finder" to set name of startup disk to diskName