Aquí hay un simple controlador que, almohadillas basadas en su pregunta.
Ejemplo de código AppleScript:
set theNumber to 1
set theNumber to padNumberAsString(theNumber)
on padNumberAsString(n)
set theLength to (get length of (n as string))
if theLength is equal to 1 then
set n to "000" & n
else if theLength is equal to 2 then
set n to "00" & n
else if theLength is equal to 3 then
set n to "0" & n
end if
return n
end padNumberAsString
Resultado: "0001"
Como demostración, esto crea y muestra una lista de los números acolchados entre 0 y 1000 para mostrar el relleno está teniendo lugar.
set thePaddedList to {}
repeat with i from 0 to 1000
set end of thePaddedList to padNumberAsString(i)
end repeat
choose from list thePaddedList
on padNumberAsString(n)
set theLength to (get length of (n as string))
if theLength is equal to 1 then
set n to "000" & n
else if theLength is equal to 2 then
set n to "00" & n
else if theLength is equal to 3 then
set n to "0" & n
end if
return n
end padNumberAsString