Ok, so thanks to the help of Stefan, I solved my first hold up, which of course led to another one. I need to generate a list of filenames, in the syntax:
SanDiegoShoot001
SanDiegoShoot002, etc
I know how to concatenate the text together, but I can’t figure out how to increment the count. I intend to have the script ask for the start and end number, and then create the list based on that (I already have the file name input figured out and working). So in the above, I have “SanDiegoShoot” in a TextEdit file, and need to add the 001, 002, etc to the end, until the stop number.
Also, sometime we need 3 digit number, sometimes its 2 or 4 digits. I have the dialog asking for that working and storing to a global dialog, but I’m not sure how to integrate it into the numbering and incrementing part.
What’s the best solution?
Model: 15" MacBook Pro C2D 2.33
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
Here is a little routine to add leading zeros with a variable length
on add_leading_zero(num_index, num_digits)
set NumberString to num_index as string
set LeadZeroCount to ((num_digits as string) - (count num_index as string))
repeat LeadZeroCount times
set NumberString to "0" & NumberString
end repeat
return NumberString
end add_leading_zero
set num_index to 12
set num_digits to 5
set a to add_leading_zero(num_index, num_digits)
--> "00012"
So then, if I’m asking for the values from my user, I would store the end number as num_index and the digits needed to num_digits, right? Now that I think of it … a starting shouldn’t be needed, although I guess it wouldn’t hurt to have it.
Ok, so I understand how it works, now I just need to figure out how to make it repeat X amount of time, so that it generates my list. This is what I have:
--Numerical Controls
on add_leading_zero(num_index, num_digits)
set NumberString to num_index as string
set LeadZeroCount to ((num_digits as string) - (count num_index as string))
repeat LeadZeroCount times
set NumberString to "0" & NumberString
end repeat
return NumberString
end add_leading_zero
set num_index to 1
set num_digits to digits_In_Scheme
set zero_Lead to add_leading_zero(num_index, num_digits)
--Insert new formatted File Name's
tell application "TextEdit"
tell document 2
set its text to leader & "/" & file_Name & zero_Lead & ending & return
end tell
end tell
And I think all I need to do is repeat the document tell X times while incrementing the zero_Lead by 1 each time. I think.
If the numbers always start from 1, you can omit it.
Anyway you need a variable to increment the value
Here an schematic example:
set num_index to 1
set end_number to get_end_number
repeat end_number times
set numberString to add_leading_zero(num_index, end_number)
-- code to process numberString
set num_index to num_index + 1
end repeat
on add_leading_zero(num_index, num_digits)
set NumberString to num_index as string
set LeadZeroCount to ((num_digits as string) - (count num_index as string))
repeat LeadZeroCount times
set NumberString to "0" & NumberString
end repeat
return NumberString
end add_leading_zero
set theText to ""
set num_index to 1
set num_digits to digits_In_Scheme
repeat |???| times
set zero_Lead to add_leading_zero(num_index, num_digits)
set theText to theText & leader & "/" & file_Name & zero_Lead & ending & return
set num_index to num_index + 1
end repeat
--Insert new formatted File Name's
tell application "TextEdit"
tell document 2
set its text to theText
end tell
end tell