Hello Guys,
I have been exploring this site for ages…
And I Love It
You guys have always supply answer with out me asking any question…
But now I’m stuck in a jam and I need help
Yes I have search and search and search but nothing works in what I’m trying to do
So please HELP and thank you very very very much in advance…
Q? : I’m creating Applescript that go’s to get files and rename theme a special way…
Here’s a example of what I have :
WBHregu20130527 1.pdf
WBHregu20130527 2.pdf
WBHregu20130527 39.pdf
WBHregu20130527 148.pdf
and I need to rename theme like this :
wbh0regu20130527001.pdf
wbh0regu20130527002.pdf
wbh0regu20130527039.pdf
wbh0regu20130527148.pdf
Ok…
For so far I manage to change the “WBH” for “wbh0”
But I can’t find a way to get rid of the space and stick the page number with a leading of 3 digits in all
[from this “…27 1.pdf” to this "…27001.pdf’] or [from this “…27 39.pdf” to this "…27039.pdf’] or [from this “…27 148.pdf” to this "…27148.pdf’]
I’m all ready using this for the rename of the “WBH” to “wbh0”
try
tell application "Finder" to set the source_folder to folder ("wbh0regu" & datadate2) of folder "beloeil_WBH" of folder datadate2 of folder "BAC_MONTEREGIE" of folder "JeqProd" of disk "InnografW" as alias
end try
set the search_parameter to the "File Names"
set the search_string to the "WBH"
set the replacement_string to the "wbh0"
set the item_list to list folder source_folder without invisibles
set source_folder to source_folder as string
repeat with i from 1 to number of items in the item_list
set this_item to item i of the item_list
set this_item to (source_folder & this_item) as alias
set this_info to info for this_item
set the current_name to the name of this_info
set change_flag to false
if the current_name contains the search_string then
if the search_parameter is "File Names" and ¬
folder of this_info is false then
set the change_flag to true
end if
if the change_flag is true then
-- replace target string using delimiters
set AppleScript's text item delimiters to the search_string
set the text_item_list to every text item of the current_name
set AppleScript's text item delimiters to the replacement_string
set the new_item_name to the text_item_list as string
set AppleScript's text item delimiters to ""
my set_item_name_wbh_B(this_item, new_item_name)
end if
end if
end repeat
on set_item_name_wbh_B(this_item, new_item_name)
tell application "Finder"
--activate
set the parent_container_path to (the container of this_item) as text
if not (exists item (the parent_container_path & new_item_name)) then
try
set the name of this_item to new_item_name
on error the error_message number the error_number
if the error_number is -59 then
set the error_message to "This name contains improper characters, such as a colon (:)."
else --the suggested name is too long
set the error_message to error_message -- "The name is more than 31 characters long."
end if
tell me to display dialog the error_message default answer new_item_name buttons {"Cancel", "Skip", "OK"} default button 3
copy the result as list to {new_item_name, button_pressed}
if the button_pressed is "Skip" then return 0
my set_item_name_wbh_B(this_item, new_item_name)
end try
end if
end tell
end set_item_name_wbh_B
Any other suggestion to even make this script shorter be appreciated… Because I have over 80 kings of “WBH” “WBR” “WCG” and so on…
Thank you again for ANY HELP
Joel St-Onge
joelstonge@mac.com