Document Renamer(s) - Is there a way to combine these two scripts?

Hi guys,

So I have 2 perfectly fine, well running scripts. Both do very similar things, in pretty much the exact same ways, but the difference between the two is fairly important.

Script 1 - document renamer - takes an existing document with the following naming convention (COUNTRY_LANGUAGE_ABBREVIATION-COURSE_COMPONENT, so for examples USA_EN_MDVT-WEA_Script) and allows you to change everything in the file name that occurs PRIOR to the n-dash (this guy “-”). Code is below (and long, sorry. I consider myself a not-very-subtle coder).



--here the user identifies the country they want and the Applescript formats that input to reflect what we want to see in the filename

set country_code to "NULL"
set country_choices to {"Afghanistan", "Albania", "Algeria", "Andorra", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Bulgaria", "Canada", "Chad", "Chile", "China", "Colombia", "Comoros", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech", "Denmark", "Djibouti", "Dominican", "Ecuador", "Egypt", "El Salvador", "Eritrea", "Estonia", "Ethiopia", "Europe", "Finland", "France", "Germany", "Ghana", "Greece", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Korea", "Kuwait", "Latvia", "Lebanon", "Liberia", "Libya", "Lithuania", "Madagascar", "Malawi", "Malaysia", "Mauritius", "Mexico", "Moldova", "Monaco", "Morocco", "Mozambique", "Namibia", "Netherlands", "New Zealand", "Nigeria", "Norway", "Oman", "Pakistan", "Peru", "Philippines", "Poland", "Portugal", "Puerto Rico", "Qatar", "Romania", "Russia", "Saudi Arabia", "Serbia", "Singapore", "Slovakia", "Slovenia", "South Africa", "Spain", "Sudan", "Sweden", "Switzerland", "Taiwan", "Tanzania", "Thailand", "Tunisia", "Turkey", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vietnam", "Yemen", "Zambia", "Zimbabwe", "Ethiopia"}

set country_chosen to (choose from list country_choices with prompt "Please select the country:")
if country_chosen is false then error number -128

--this converts the user's selection into the appropriate country code

if item 1 of country_chosen is item 1 of country_choices then
	set country_code to "AFG"
else if item 1 of country_chosen is item 2 of country_choices then
	set country_code to "ALB"
else if item 1 of country_chosen is item 3 of country_choices then
	set country_code to "DZA"
else if item 1 of country_chosen is item 4 of country_choices then
	set country_code to "AND"
else if item 1 of country_chosen is item 5 of country_choices then
	set country_code to "ARG"
else if item 1 of country_chosen is item 6 of country_choices then
	set country_code to "ARM"
else if item 1 of country_chosen is item 7 of country_choices then
	set country_code to "ABW"
else if item 1 of country_chosen is item 8 of country_choices then
	set country_code to "AUS"
else if item 1 of country_chosen is item 9 of country_choices then
	set country_code to "AUT"
else if item 1 of country_chosen is item 10 of country_choices then
	set country_code to "AZE"
else if item 1 of country_chosen is item 11 of country_choices then
	set country_code to "BHS"
else if item 1 of country_chosen is item 12 of country_choices then
	set country_code to "BLR"
else if item 1 of country_chosen is item 13 of country_choices then
	set country_code to "BEL"
else if item 1 of country_chosen is item 14 of country_choices then
	set country_code to "BLZ"
else if item 1 of country_chosen is item 15 of country_choices then
	set country_code to "BEN"
else if item 1 of country_chosen is item 16 of country_choices then
	set country_code to "BMU"
else if item 1 of country_chosen is item 17 of country_choices then
	set country_code to "BTN"
else if item 1 of country_chosen is item 18 of country_choices then
	set country_code to "BOL"
else if item 1 of country_chosen is item 19 of country_choices then
	set country_code to "BIH"
else if item 1 of country_chosen is item 20 of country_choices then
	set country_code to "BWA"
else if item 1 of country_chosen is item 21 of country_choices then
	set country_code to "BRA"
else if item 1 of country_chosen is item 22 of country_choices then
	set country_code to "BGR"
else if item 1 of country_chosen is item 23 of country_choices then
	set country_code to "CAN"
else if item 1 of country_chosen is item 24 of country_choices then
	set country_code to "TCD"
else if item 1 of country_chosen is item 25 of country_choices then
	set country_code to "CHL"
else if item 1 of country_chosen is item 26 of country_choices then
	set country_code to "CHN"
else if item 1 of country_chosen is item 27 of country_choices then
	set country_code to "COL"
else if item 1 of country_chosen is item 28 of country_choices then
	set country_code to "COM"
else if item 1 of country_chosen is item 29 of country_choices then
	set country_code to "CRI"
else if item 1 of country_chosen is item 30 of country_choices then
	set country_code to "HRV"
else if item 1 of country_chosen is item 31 of country_choices then
	set country_code to "CUB"
else if item 1 of country_chosen is item 32 of country_choices then
	set country_code to "CYP"
else if item 1 of country_chosen is item 33 of country_choices then
	set country_code to "CZE"
else if item 1 of country_chosen is item 34 of country_choices then
	set country_code to "DNK"
else if item 1 of country_chosen is item 35 of country_choices then
	set country_code to "DJI"
else if item 1 of country_chosen is item 36 of country_choices then
	set country_code to "DOM"
else if item 1 of country_chosen is item 37 of country_choices then
	set country_code to "ECU"
else if item 1 of country_chosen is item 38 of country_choices then
	set country_code to "EGY"
else if item 1 of country_chosen is item 39 of country_choices then
	set country_code to "SLV"
else if item 1 of country_chosen is item 40 of country_choices then
	set country_code to "ERI"
else if item 1 of country_chosen is item 41 of country_choices then
	set country_code to "EST"
else if item 1 of country_chosen is item 42 of country_choices then
	set country_code to "ETH"
else if item 1 of country_chosen is item 43 of country_choices then
	set country_code to "GEU"
else if item 1 of country_chosen is item 44 of country_choices then
	set country_code to "FIN"
else if item 1 of country_chosen is item 45 of country_choices then
	set country_code to "FRA"
else if item 1 of country_chosen is item 46 of country_choices then
	set country_code to "DEU"
else if item 1 of country_chosen is item 47 of country_choices then
	set country_code to "GHA"
else if item 1 of country_chosen is item 48 of country_choices then
	set country_code to "GRC"
else if item 1 of country_chosen is item 49 of country_choices then
	set country_code to "HKG"
else if item 1 of country_chosen is item 50 of country_choices then
	set country_code to "HUN"
else if item 1 of country_chosen is item 51 of country_choices then
	set country_code to "ISL"
else if item 1 of country_chosen is item 52 of country_choices then
	set country_code to "IND"
else if item 1 of country_chosen is item 53 of country_choices then
	set country_code to "IDN"
else if item 1 of country_chosen is item 54 of country_choices then
	set country_code to "IRN"
else if item 1 of country_chosen is item 55 of country_choices then
	set country_code to "IRQ"
else if item 1 of country_chosen is item 56 of country_choices then
	set country_code to "IRL"
else if item 1 of country_chosen is item 57 of country_choices then
	set country_code to "ISR"
else if item 1 of country_chosen is item 58 of country_choices then
	set country_code to "ITA"
else if item 1 of country_chosen is item 59 of country_choices then
	set country_code to "JAM"
else if item 1 of country_chosen is item 60 of country_choices then
	set country_code to "JPN"
else if item 1 of country_chosen is item 61 of country_choices then
	set country_code to "JOR"
else if item 1 of country_chosen is item 62 of country_choices then
	set country_code to "KAZ"
else if item 1 of country_chosen is item 63 of country_choices then
	set country_code to "KEN"
else if item 1 of country_chosen is item 64 of country_choices then
	set country_code to "KOR"
else if item 1 of country_chosen is item 65 of country_choices then
	set country_code to "KWT"
else if item 1 of country_chosen is item 66 of country_choices then
	set country_code to "LVA"
else if item 1 of country_chosen is item 67 of country_choices then
	set country_code to "LBN"
else if item 1 of country_chosen is item 68 of country_choices then
	set country_code to "LBR"
else if item 1 of country_chosen is item 69 of country_choices then
	set country_code to "LBY"
else if item 1 of country_chosen is item 70 of country_choices then
	set country_code to "LTU"
else if item 1 of country_chosen is item 71 of country_choices then
	set country_code to "MDG"
else if item 1 of country_chosen is item 72 of country_choices then
	set country_code to "MWI"
else if item 1 of country_chosen is item 73 of country_choices then
	set country_code to "MYS"
else if item 1 of country_chosen is item 74 of country_choices then
	set country_code to "MUS"
else if item 1 of country_chosen is item 75 of country_choices then
	set country_code to "MEX"
else if item 1 of country_chosen is item 76 of country_choices then
	set country_code to "MDA"
else if item 1 of country_chosen is item 77 of country_choices then
	set country_code to "MCO"
else if item 1 of country_chosen is item 78 of country_choices then
	set country_code to "MAR"
else if item 1 of country_chosen is item 79 of country_choices then
	set country_code to "MOZ"
else if item 1 of country_chosen is item 80 of country_choices then
	set country_code to "NAM"
else if item 1 of country_chosen is item 81 of country_choices then
	set country_code to "NLD"
else if item 1 of country_chosen is item 82 of country_choices then
	set country_code to "NZL"
else if item 1 of country_chosen is item 83 of country_choices then
	set country_code to "NGA"
else if item 1 of country_chosen is item 84 of country_choices then
	set country_code to "NOR"
else if item 1 of country_chosen is item 85 of country_choices then
	set country_code to "OMN"
else if item 1 of country_chosen is item 86 of country_choices then
	set country_code to "PAK"
else if item 1 of country_chosen is item 87 of country_choices then
	set country_code to "PER"
else if item 1 of country_chosen is item 88 of country_choices then
	set country_code to "PHL"
else if item 1 of country_chosen is item 89 of country_choices then
	set country_code to "POL"
else if item 1 of country_chosen is item 90 of country_choices then
	set country_code to "PRT"
else if item 1 of country_chosen is item 91 of country_choices then
	set country_code to "PRI"
else if item 1 of country_chosen is item 92 of country_choices then
	set country_code to "QAT"
else if item 1 of country_chosen is item 93 of country_choices then
	set country_code to "ROM"
else if item 1 of country_chosen is item 94 of country_choices then
	set country_code to "RUS"
else if item 1 of country_chosen is item 95 of country_choices then
	set country_code to "SAU"
else if item 1 of country_chosen is item 96 of country_choices then
	set country_code to "SRB"
else if item 1 of country_chosen is item 97 of country_choices then
	set country_code to "SGP"
else if item 1 of country_chosen is item 98 of country_choices then
	set country_code to "SVK"
else if item 1 of country_chosen is item 99 of country_choices then
	set country_code to "SVN"
else if item 1 of country_chosen is item 100 of country_choices then
	set country_code to "ZAF"
else if item 1 of country_chosen is item 101 of country_choices then
	set country_code to "ESP"
else if item 1 of country_chosen is item 102 of country_choices then
	set country_code to "SDN"
else if item 1 of country_chosen is item 103 of country_choices then
	set country_code to "SWE"
else if item 1 of country_chosen is item 104 of country_choices then
	set country_code to "CHE"
else if item 1 of country_chosen is item 105 of country_choices then
	set country_code to "TWN"
else if item 1 of country_chosen is item 106 of country_choices then
	set country_code to "TZA"
else if item 1 of country_chosen is item 107 of country_choices then
	set country_code to "THA"
else if item 1 of country_chosen is item 108 of country_choices then
	set country_code to "TUN"
else if item 1 of country_chosen is item 109 of country_choices then
	set country_code to "TUR"
else if item 1 of country_chosen is item 110 of country_choices then
	set country_code to "UKR"
else if item 1 of country_chosen is item 111 of country_choices then
	set country_code to "ARE"
else if item 1 of country_chosen is item 112 of country_choices then
	set country_code to "GBR"
else if item 1 of country_chosen is item 113 of country_choices then
	set country_code to "USA"
else if item 1 of country_chosen is item 114 of country_choices then
	set country_code to "URY"
else if item 1 of country_chosen is item 115 of country_choices then
	set country_code to "UZB"
else if item 1 of country_chosen is item 116 of country_choices then
	set country_code to "VNM"
else if item 1 of country_chosen is item 117 of country_choices then
	set country_code to "YEM"
else if item 1 of country_chosen is item 118 of country_choices then
	set country_code to "ZMB"
else if item 1 of country_chosen is item 119 of country_choices then
	set country_code to "ZWE"
end if

--------------------------------------------------------------------------

--here the user selects the language code they need it to save as

set language_code to "NULL"
set language_choices to {"Arabic (AR)", "Amharic (AM)", "Armenian (HY)", "Azerbaijani (AZ)", "Belarusian (BE)", "Bosnian (BS)", "Bulgarian (BG)", "Chinese (ZH)", "Croatian (HR)", "Czech (CS)", "Danish (DA)", "Dutch (NL)", "English (EN)", "Estonian (ET)", "Farsi (FA)", "Finnish (FI)", "French (FR)", "German (DE)", "Greek (EL)", "Hebrew (HE)", "Hindi (HI)", "Hungarian (HU)", "Indonesian (ID)", "Italian (IT)", "Japanese (JP)", "Kazakh (KK)", "Korean (KO)", "Latvian (LV)", "Lithuanian (LT)", "Malay (MS)", "Norwegian (NO)", "Polish (PL)", "Portuguese (PT)", "Romanian (RO)", "Russian (RU)", "Serbian (SR)", "Slovak (SK)", "Spanish (ES)", "Swahili (SW)", "Swedish (SV)", "Thai (TH)", "Turkish (TR)", "Ukrainian (UK)", "Urdu (UR)", "Vietnamese (VI)"}

set language_chosen to (choose from list language_choices with prompt "Please select the language:")
if language_chosen is false then error number -128

if item 1 of language_chosen is item 1 of language_choices then
	set language_code to "AR"
else if item 1 of language_chosen is item 2 of language_choices then
	set language_code to "AM"
else if item 1 of language_chosen is item 3 of language_choices then
	set language_code to "HY"
else if item 1 of language_chosen is item 4 of language_choices then
	set language_code to "AZ"
else if item 1 of language_chosen is item 5 of language_choices then
	set language_code to "BE"
else if item 1 of language_chosen is item 6 of language_choices then
	set language_code to "BS"
else if item 1 of language_chosen is item 7 of language_choices then
	set language_code to "BG"
else if item 1 of language_chosen is item 8 of language_choices then
	set language_code to "ZH"
else if item 1 of language_chosen is item 9 of language_choices then
	set language_code to "HR"
else if item 1 of language_chosen is item 10 of language_choices then
	set language_code to "CS"
else if item 1 of language_chosen is item 11 of language_choices then
	set language_code to "DA"
else if item 1 of language_chosen is item 12 of language_choices then
	set language_code to "NL"
else if item 1 of language_chosen is item 13 of language_choices then
	set language_code to "EN"
else if item 1 of language_chosen is item 14 of language_choices then
	set language_code to "ET"
else if item 1 of language_chosen is item 15 of language_choices then
	set language_code to "FA"
else if item 1 of language_chosen is item 16 of language_choices then
	set language_code to "FI"
else if item 1 of language_chosen is item 17 of language_choices then
	set language_code to "FR"
else if item 1 of language_chosen is item 18 of language_choices then
	set language_code to "DE"
else if item 1 of language_chosen is item 19 of language_choices then
	set language_code to "EL"
else if item 1 of language_chosen is item 20 of language_choices then
	set language_code to "HE"
else if item 1 of language_chosen is item 21 of language_choices then
	set language_code to "HI"
else if item 1 of language_chosen is item 22 of language_choices then
	set language_code to "HU"
else if item 1 of language_chosen is item 23 of language_choices then
	set language_code to "ID"
else if item 1 of language_chosen is item 24 of language_choices then
	set language_code to "IT"
else if item 1 of language_chosen is item 25 of language_choices then
	set language_code to "JP"
else if item 1 of language_chosen is item 26 of language_choices then
	set language_code to "KK"
else if item 1 of language_chosen is item 27 of language_choices then
	set language_code to "KO"
else if item 1 of language_chosen is item 28 of language_choices then
	set language_code to "LV"
else if item 1 of language_chosen is item 29 of language_choices then
	set language_code to "LT"
else if item 1 of language_chosen is item 30 of language_choices then
	set language_code to "MS"
else if item 1 of language_chosen is item 31 of language_choices then
	set language_code to "NO"
else if item 1 of language_chosen is item 32 of language_choices then
	set language_code to "PL"
else if item 1 of language_chosen is item 33 of language_choices then
	set language_code to "PT"
else if item 1 of language_chosen is item 34 of language_choices then
	set language_code to "RO"
else if item 1 of language_chosen is item 35 of language_choices then
	set language_code to "RU"
else if item 1 of language_chosen is item 36 of language_choices then
	set language_code to "SR"
else if item 1 of language_chosen is item 37 of language_choices then
	set language_code to "SK"
else if item 1 of language_chosen is item 38 of language_choices then
	set language_code to "ES"
else if item 1 of language_chosen is item 39 of language_choices then
	set language_code to "SW"
else if item 1 of language_chosen is item 40 of language_choices then
	set language_code to "SV"
else if item 1 of language_chosen is item 41 of language_choices then
	set language_code to "TH"
else if item 1 of language_chosen is item 42 of language_choices then
	set language_code to "TR"
else if item 1 of language_chosen is item 43 of language_choices then
	set language_code to "UK"
else if item 1 of language_chosen is item 44 of language_choices then
	set language_code to "UR"
else if item 1 of language_chosen is item 45 of language_choices then
	set language_code to "VI"
end if

--------------------------------------------------------------------------

--here the user identifies any vehicle-type abbreviation they'd like to input between the language code and the module code.

display dialog "Please enter the vehicle type abbreviation you would like to use. It must be in all caps, and must only be letters only. Not special characters. Examples include 'CP' for 'Cherry Picker', 'T' for 'Trucks', or 'MDVT' for 'Medium Duty Vocational Trucks'" default answer ""
set vehicle_abbreviation to text returned of result

--here the new prefix for all the documents is created based on all the user input. It will be something like "USA_EN_MDVT-" depending on the country, language, and abbreviation the user enters. The format, however, will always be the same (county_language_abbrev-).

set document_prefix to (country_code & "_" & language_code & "_" & vehicle_abbreviation & "-")



--here the user selects the files they want to rename. They can make multiple selections, choosing every file in the folder if they want. This first part specifically removes the existing prefix in files where there is an n-dash.

set Docs_to_be_renamed to (choose file with multiple selections allowed)
repeat with aFile in Docs_to_be_renamed
	set aFile to contents of aFile
	tell application "Finder"
		set fileName to aFile's name
		set firstDash to offset of "-" in fileName
		set aFile's name to text (firstDash + 1) through -1 of fileName
	end tell
end repeat


--this repeat makes sure all the files that were selected are renamed to include the new prefix

repeat with aFile in Docs_to_be_renamed
	set aFile to contents of aFile
	tell application "Finder"
		set aFile's name to (document_prefix & aFile's name)
	end tell
end repeat

display dialog "Renaming complete."

The second version of this code, Script 2, allows users to add that abbreviation that occurs before the n-dash if it’s not already present in the file name (a switch over in naming conventions had necessitated this) It’s code is EXACTLY the same as the above with the exception of how it identifies where to put the prefix, that code is as follows:



set Docs_to_be_renamed to (choose file with multiple selections allowed)
repeat with aFile in Docs_to_be_renamed
	set aFile to contents of aFile
	tell application "Finder"
		set fileName to aFile's name
		set secondUnder to offset of "_" in fileName
		set aFile's name to text (secondUnder + 4) through -1 of fileName
	end tell
end repeat


Ultimately, I guess my question is this: any thoughts on how I can make these two scripts into one? I just feel like one super-script is a little more user-friendly (and utilitarian) than 2 scripts that do almost exactly the same thing.

Thanks for any help and ideas you guys have!

If I understood well the question, you may try:



--here the user identifies the country they want and the Applescript formats that input to reflect what we want to see in the filename

set country_code to "NULL"
set country_choices to {"Afghanistan", "Albania", "Algeria", "Andorra", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Bulgaria", "Canada", "Chad", "Chile", "China", "Colombia", "Comoros", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech", "Denmark", "Djibouti", "Dominican", "Ecuador", "Egypt", "El Salvador", "Eritrea", "Estonia", "Ethiopia", "Europe", "Finland", "France", "Germany", "Ghana", "Greece", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Korea", "Kuwait", "Latvia", "Lebanon", "Liberia", "Libya", "Lithuania", "Madagascar", "Malawi", "Malaysia", "Mauritius", "Mexico", "Moldova", "Monaco", "Morocco", "Mozambique", "Namibia", "Netherlands", "New Zealand", "Nigeria", "Norway", "Oman", "Pakistan", "Peru", "Philippines", "Poland", "Portugal", "Puerto Rico", "Qatar", "Romania", "Russia", "Saudi Arabia", "Serbia", "Singapore", "Slovakia", "Slovenia", "South Africa", "Spain", "Sudan", "Sweden", "Switzerland", "Taiwan", "Tanzania", "Thailand", "Tunisia", "Turkey", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vietnam", "Yemen", "Zambia", "Zimbabwe", "Ethiopia"}

set country_chosen to (choose from list country_choices with prompt "Please select the country:")
if country_chosen is false then error number -128

--this converts the user's selection into the appropriate country code

set country_codes to {"AFG", "ALB", "DZA", "AND", "ARG", "ARM", "ABW", "AUS", "AUT", "AZE", "BHS", "BLR", "BEL", "BLZ", "BEN", "BMU", "BTN", "BOL", "BIH", "BWA", "BRA", "BGR", "CAN", "TCD", "CHL", "CHN", "COL", "COM", "CRI", "HRV", "CUB", "CYP", "CZE", "DNK", "DJI", "DOM", "ECU", "EGY", "SLV", "ERI", "EST", "ETH", "GEU", "FIN", "FRA", "DEU", "GHA", "GRC", "HKG", "HUN", "ISL", "IND", "IDN", "IRN", "IRQ", "IRL", "ISR", "ITA", "JAM", "JPN", "JOR", "KAZ", "KEN", "KOR", "KWT", "LVA", "LBN", "LBR", "LBY", "LTU", "MDG", "MWI", "MYS", "MUS", "MEX", "MDA", "MCO", "MAR", "MOZ", "NAM", "NLD", "NZL", "NGA", "NOR", "OMN", "PAK", "PER", "PHL", "POL", "PRT", "PRI", "QAT", "ROM", "RUS", "SAU", "SRB", "SGP", "SVK", "SVN", "ZAF", "ESP", "SDN", "SWE", "CHE", "TWN", "TZA", "THA", "TUN", "TUR", "UKR", "ARE", "GBR", "USA", "URY", "UZB", "VNM", "YEM", "ZMB", "ZWE", "ETH"} # Your original code failed to treat the case : Ethiopia --> ETH
return {count country_choices, count country_codes}
set country_chosen to item 1 of country_chosen
repeat with aCode in country_codes
	if country_chosen is aCode as text then
		set country_code to aCode
		exit repeat
	end if
end repeat

--------------------------------------------------------------------------

--here the user selects the language code they need it to save as

set language_code to "NULL"
set language_choices to {"Arabic (AR)", "Amharic (AM)", "Armenian (HY)", "Azerbaijani (AZ)", "Belarusian (BE)", "Bosnian (BS)", "Bulgarian (BG)", "Chinese (ZH)", "Croatian (HR)", "Czech (CS)", "Danish (DA)", "Dutch (NL)", "English (EN)", "Estonian (ET)", "Farsi (FA)", "Finnish (FI)", "French (FR)", "German (DE)", "Greek (EL)", "Hebrew (HE)", "Hindi (HI)", "Hungarian (HU)", "Indonesian (ID)", "Italian (IT)", "Japanese (JP)", "Kazakh (KK)", "Korean (KO)", "Latvian (LV)", "Lithuanian (LT)", "Malay (MS)", "Norwegian (NO)", "Polish (PL)", "Portuguese (PT)", "Romanian (RO)", "Russian (RU)", "Serbian (SR)", "Slovak (SK)", "Spanish (ES)", "Swahili (SW)", "Swedish (SV)", "Thai (TH)", "Turkish (TR)", "Ukrainian (UK)", "Urdu (UR)", "Vietnamese (VI)"}

set language_chosen to (choose from list language_choices with prompt "Please select the language:")
if language_chosen is false then error number -128

set language_code to items -3 thru -2 of item 1 of language_chosen as text

--------------------------------------------------------------------------

--here the user identifies any vehicle-type abbreviation they'd like to input between the language code and the module code.

display dialog "Please enter the vehicle type abbreviation you would like to use. It must be in all caps, and must only be letters only. Not special characters. Examples include 'CP' for 'Cherry Picker', 'T' for 'Trucks', or 'MDVT' for 'Medium Duty Vocational Trucks'" default answer ""
set vehicle_abbreviation to text returned of result

--here the new prefix for all the documents is created based on all the user input. It will be something like "USA_EN_MDVT-" depending on the country, language, and abbreviation the user enters. The format, however, will always be the same (county_language_abbrev-).

set document_prefix to (country_code & "_" & language_code & "_" & vehicle_abbreviation & "-")



--here the user selects the files they want to rename. They can make multiple selections, choosing every file in the folder if they want. This first part specifically removes the existing prefix in files where there is an n-dash.

set Docs_to_be_renamed to (choose file with multiple selections allowed)
repeat with aFile in Docs_to_be_renamed
	set aFile to contents of aFile
	tell application "Finder"
		set fileName to aFile's name
		if fileName contains "-" then
			set firstDash to offset of "-" in fileName
			set aFile's name to text (firstDash + 1) through -1 of fileName
		else if fileName contains "_" then
			set secondUnder to offset of "_" in fileName
			set aFile's name to text (secondUnder + 4) through -1 of fileName
		end if
	end tell
end repeat

--this repeat makes sure all the files that were selected are renamed to include the new prefix

repeat with aFile in Docs_to_be_renamed
	set aFile to contents of aFile
	tell application "Finder"
		set aFile's name to (document_prefix & aFile's name)
	end tell
end repeat

display dialog "Renaming complete."

As you may see I made some small changes and corrected an error : you missed to define the code for Ethiopia.

Yvan KOENIG running Sierra 10.12.1 in French (VALLAURIS, France) lundi 28 novembre 2016 16:33:58

I can’t believe I didn’t think of that. Wow.

But thank you so much!

This version should work better as an example of your first script.



--here the user identifies the country they want and the Applescript formats that input to reflect what we want to see in the filename

set country_code to "NULL"
set country_choices to {"Afghanistan", "Albania", "Algeria", "Andorra", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Bulgaria", "Canada", "Chad", "Chile", "China", "Colombia", "Comoros", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech", "Denmark", "Djibouti", "Dominican", "Ecuador", "Egypt", "El Salvador", "Eritrea", "Estonia", "Ethiopia", "Europe", "Finland", "France", "Germany", "Ghana", "Greece", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Korea", "Kuwait", "Latvia", "Lebanon", "Liberia", "Libya", "Lithuania", "Madagascar", "Malawi", "Malaysia", "Mauritius", "Mexico", "Moldova", "Monaco", "Morocco", "Mozambique", "Namibia", "Netherlands", "New Zealand", "Nigeria", "Norway", "Oman", "Pakistan", "Peru", "Philippines", "Poland", "Portugal", "Puerto Rico", "Qatar", "Romania", "Russia", "Saudi Arabia", "Serbia", "Singapore", "Slovakia", "Slovenia", "South Africa", "Spain", "Sudan", "Sweden", "Switzerland", "Taiwan", "Tanzania", "Thailand", "Tunisia", "Turkey", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vietnam", "Yemen", "Zambia", "Zimbabwe"}
set cc to {"AFG", "ALB", "DZA", "AND", "ARG", "ARM", "ABW", "AUS", "AUT", "AZE", "BHS", "BLR", "BEL", "BLZ", "BEN", "BMU", "BTN", "BOL", "BIH", "BWA", "BRA", "BGR", "CAN", "TCD", "CHL", "CHN", "COL", "COM", "CRI", "HRV", "CUB", "CYP", "CZE", "DNK", "DJI", "DOM", "ECU", "EGY", "SLV", "ERI", "EST", "ETH", "GEU", "FIN", "FRA", "DEU", "GHA", "GRC", "HKG", "HUN", "ISL", "IND", "IDN", "IRN", "IRQ", "IRL", "ISR", "ITA", "JAM", "JPN", "JOR", "KAZ", "KEN", "KOR", "KWT", "LVA", "LBN", "LBR", "LBY", "LTU", "MDG", "MWI", "MYS", "MUS", "MEX", "MDA", "MCO", "MAR", "MOZ", "NAM", "NLD", "NZL", "NGA", "NOR", "OMN", "PAK", "PER", "PHL", "POL", "PRT", "PRI", "QAT", "ROM", "RUS", "SAU", "SRB", "SGP", "SVK", "SVN", "ZAF", "ESP", "SDN", "SWE", "CHE", "TWN", "TZA", "THA", "TUN", "TUR", "UKR", "ARE", "GBR", "USA", "URY", "UZB", "VNM", "YEM", "ZMB", "ZWE"}

set country_chosen to (choose from list country_choices with prompt "Please select the country:")
if country_chosen is false then error number -128

--this converts the user's selection into the appropriate country code
repeat with i from 1 to count of country_choices
	if item 1 of country_chosen is item i of country_choices then
		set country_code to item i of cc
		exit repeat
	end if
end repeat

--------------------------------------------------------------------------

--here the user selects the language code they need it to save as

set language_code to "NULL"
set language_choices to {"Arabic (AR)", "Amharic (AM)", "Armenian (HY)", "Azerbaijani (AZ)", "Belarusian (BE)", "Bosnian (BS)", "Bulgarian (BG)", "Chinese (ZH)", "Croatian (HR)", "Czech (CS)", "Danish (DA)", "Dutch (NL)", "English (EN)", "Estonian (ET)", "Farsi (FA)", "Finnish (FI)", "French (FR)", "German (DE)", "Greek (EL)", "Hebrew (HE)", "Hindi (HI)", "Hungarian (HU)", "Indonesian (ID)", "Italian (IT)", "Japanese (JP)", "Kazakh (KK)", "Korean (KO)", "Latvian (LV)", "Lithuanian (LT)", "Malay (MS)", "Norwegian (NO)", "Polish (PL)", "Portuguese (PT)", "Romanian (RO)", "Russian (RU)", "Serbian (SR)", "Slovak (SK)", "Spanish (ES)", "Swahili (SW)", "Swedish (SV)", "Thai (TH)", "Turkish (TR)", "Ukrainian (UK)", "Urdu (UR)", "Vietnamese (VI)"}

set language_chosen to (choose from list language_choices with prompt "Please select the language:")
if language_chosen is false then error number -128
set text item delimiters to {"(", ")"}
set language_code to text item 2 of item 1 of language_chosen
set text item delimiters to ""

--------------------------------------------------------------------------

--here the user identifies any vehicle-type abbreviation they'd like to input between the language code and the module code.

display dialog "Please enter the vehicle type abbreviation you would like to use. It must be in all caps, and must only be letters only. Not special characters. Examples include 'CP' for 'Cherry Picker', 'T' for 'Trucks', or 'MDVT' for 'Medium Duty Vocational Trucks'" default answer ""
set vehicle_abbreviation to text returned of result

--here the new prefix for all the documents is created based on all the user input. It will be something like "USA_EN_MDVT-" depending on the country, language, and abbreviation the user enters. The format, however, will always be the same (county_language_abbrev-).

set document_prefix to (country_code & "_" & language_code & "_" & vehicle_abbreviation & "-")



--here the user selects the files they want to rename. They can make multiple selections, choosing every file in the folder if they want. This first part specifically removes the existing prefix in files where there is an n-dash.

set Docs_to_be_renamed to (choose file with multiple selections allowed)
repeat with aFile in Docs_to_be_renamed
	set aFile to contents of aFile
	tell application "Finder"
		set fileName to aFile's name
		set firstDash to offset of "-" in fileName
		set aFile's name to text (firstDash + 1) through -1 of fileName
	end tell
end repeat


--this repeat makes sure all the files that were selected are renamed to include the new prefix

repeat with aFile in Docs_to_be_renamed
	set aFile to contents of aFile
	tell application "Finder"
		set aFile's name to (document_prefix & aFile's name)
	end tell
end repeat

display dialog "Renaming complete."