【AppleScript】数値の文字列をゼロ詰めする


my packZero({val_:"5", len_:2}) -- (*05*)
my packZero({val_:99 as text, len_:3}) -- (*099*)
my packZero({val_:"11", len_:4}) -- (*0011*)

on packZero(args)

    set {val_:aVal, len_:aLen} to ¬
        args & {val_:"", len_:0}

    set zero to ""

    repeat (aLen) times

        set zero to zero & "0"

    end repeat

    set len to (count ((zero & aVal) as string)) - (aLen - 1)
    return text len thru -1 of (zero & aVal)

end packZero