Multiple selections explode and options mapping

Hi, I hope you can help me do 2 things in this script:

1 - As mainList3 allows for multiple selection, I need the countrySel output to be exploded with a comma as delimiter, so, for example: en,it,pt,fr

2 - I need the first mainList, which chooses the month, to have January, February in the selection box, but their actual value has to be 01, 02, … How can I have the values have different labels for the selection box?

choose folder with prompt "Choose destination folder"
set folderSel1 to result as text
set folderSel to POSIX path of folderSel1

set mainList to {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"}
choose from list mainList with prompt "Choose Month:"
set monthSel to result as text

set mainList2 to {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}
choose from list mainList2 with prompt "Choose Day:"
set daySel to result as text

set mainList3 to {"en", "fr", "de", "nl", "it", "es", "pl", "hu", "cs", "pl", "pt", "no", "sv", "jp", "zh_CN", "zh_TW", "ko"}
choose from list mainList3 with prompt "Choose Country:" with multiple selections allowed
set countrySel to result as text

set Tcommand to "/Applications/Everyday" & "\\ " & "Icon.app/Contents/Resources/EverydayIconTool -l " & countrySel & " -m " & monthSel & " -d " & daySel & " -t " & folderSel

tell application "Terminal"
	do script Tcommand in window 1
end tell

Thanks

Hi,

if you can live with the abbreviations of the months, this is the easiest solution


set folderSel to quoted form of POSIX path of (choose folder with prompt "Choose destination folder")

set mainList to {January, February, March, April, May, June, July, August, September, October, November, December}
set monthSel to (choose from list mainList with prompt "Choose Month:")
if monthSel is false then return
set monthSel to item 1 of monthSel as integer
set monthSelAsText to text -2 thru -1 of ("0" & monthSel)

set mainList2 to {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}
set daySel to (choose from list mainList2 with prompt "Choose Day:")
if daySel is false then return
set daySel to item 1 of daySel

set mainList3 to {"en", "fr", "de", "nl", "it", "es", "pl", "hu", "cs", "pl", "pt", "no", "sv", "jp", "zh_CN", "zh_TW", "ko"}
set countrySel to (choose from list mainList3 with prompt "Choose Country:" with multiple selections allowed)
set {TID, text item delimiters} to {text item delimiters, ","}
set countrySel to countrySel as text
set text item delimiters to TID

set Tcommand to quoted form of "/Applications/Everyday Icon.app/Contents/Resources/EverydayIconTool" & " -l " & countrySel & " -m " & monthSelAsText & " -d " & daySel & " -t " & folderSel
do shell script Tcommand

Oh great, thanks Stefan!

How come it shortens the month?

What should be done to add labels to mainList3 and countrySel, so that en would have English, fr would have French, etc.?

Quite strangely, option “no” outputs “nb” instead?

the names are actually enumerated constants (integers), the text representation is the abbreviated names

This is possible with a second list, with the index from the chosen result you can get the appropriate item from the other list

Hmm, sorry how would the code be then?

something like this (excerpt)


property mainList3 : {"en", "fr", "de"}
property fullMainList3 : {"English", "French", "German"}

set fullList to {}
set countrySel to (choose from list fullMainList3 with prompt "Choose Country:" with multiple selections allowed)
if countrySel is false then return
repeat with anItem in countrySel
	set theIndex to indexOfObjectInFullList(contents of anItem)
	set end of fullList to item theIndex of mainList3
end repeat
set {TID, text item delimiters} to {text item delimiters, ","}
set fullList to fullList as text
set text item delimiters to TID

on indexOfObjectInFullList(theObject)
	repeat with i from 1 to (count fullMainList3)
		if theObject is equal to item i of fullMainList3 then return i
	end repeat
end indexOfObjectInFullList

Looks good, but it seems to return EnglishFrenchGerman instead of en,fr,de

The variable fullList contains the final result (I admit this is a misleading name)

Hmm sorry, how do I have to change it to output en,fr,de instead of EnglishFrenchGerman ?

Thanks for your help

the script in post #7 does output en,fr,de (content of variable fullList)

I must be doing something wrong then, I have this full script but it outputs EnglishFrenchGerman to me. Does it output the same to you?


set folderSel to quoted form of POSIX path of (choose folder with prompt "Choose destination folder")

set mainList to {January, February, March, April, May, June, July, August, September, October, November, December}
set monthSel to (choose from list mainList with prompt "Choose Month:")
if monthSel is false then return
set monthSel to item 1 of monthSel as integer
set monthSelAsText to text -2 thru -1 of ("0" & monthSel)

set mainList2 to {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}
set daySel to (choose from list mainList2 with prompt "Choose Day:")
if daySel is false then return
set daySel to item 1 of daySel

property mainList3 : {"en", "fr", "de"}
property fullMainList3 : {"English", "French", "German"}

set fullList to {}
set countrySel to (choose from list fullMainList3 with prompt "Choose Country:" with multiple selections allowed)
if countrySel is false then return
repeat with anItem in countrySel
	set theIndex to indexOfObjectInFullList(contents of anItem)
	set end of fullList to item theIndex of mainList3
end repeat
set {TID, text item delimiters} to {text item delimiters, ","}
set fullList to fullList as text
set text item delimiters to TID

on indexOfObjectInFullList(theObject)
	repeat with i from 1 to (count fullMainList3)
		if theObject is equal to item i of fullMainList3 then return i
	end repeat
end indexOfObjectInFullList

display dialog "Here you can see all your variables returned: " & monthSelAsText & ", " & daySel & ", " & countrySel & "  " & folderSel

set Tcommand to quoted form of "/Applications/Everyday Icon.app/Contents/Resources/EverydayIconTool" & " -l " & countrySel & " -m " & monthSelAsText & " -d " & daySel & " -t " & folderSel
do shell script Tcommand

as the variable fullList contains the proper result, replace countrySel with fullList in the display dialog line and later

Hmmm… I’m really sorry, I’m messing it up it’s now giving me English,French,German,en,fr,de :frowning:


set folderSel to quoted form of POSIX path of (choose folder with prompt "Choose destination folder")

set mainList to {January, February, March, April, May, June, July, August, September, October, November, December}
set monthSel to (choose from list mainList with prompt "Choose Month:")
if monthSel is false then return
set monthSel to item 1 of monthSel as integer
set monthSelAsText to text -2 thru -1 of ("0" & monthSel)

set mainList2 to {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}
set daySel to (choose from list mainList2 with prompt "Choose Day:")
if daySel is false then return
set daySel to item 1 of daySel

property mainList3 : {"en", "fr", "de"}
property fullMainList3 : {"English", "French", "German"}

set fullList to {}
set fullList to (choose from list fullMainList3 with prompt "Choose Country:" with multiple selections allowed)
if fullList is false then return
repeat with anItem in fullList
	set theIndex to indexOfObjectInFullList(contents of anItem)
	set end of fullList to item theIndex of mainList3
end repeat
set {TID, text item delimiters} to {text item delimiters, ","}
set fullList to fullList as text
set text item delimiters to TID

on indexOfObjectInFullList(theObject)
	repeat with i from 1 to (count fullMainList3)
		if theObject is equal to item i of fullMainList3 then return i
	end repeat
end indexOfObjectInFullList

display dialog "Here you can see all your variables returned: " & monthSelAsText & ", " & daySel & ", " & fullList & "  " & folderSel

set Tcommand to quoted form of "/Applications/Everyday Icon.app/Contents/Resources/EverydayIconTool" & " -l " & countrySel & " -m " & monthSelAsText & " -d " & daySel & " -t " & folderSel
do shell script Tcommand

replace the variable name in the next line too

set Tcommand to quoted form of "/Applications/Everyday Icon.app/Contents/Resources/EverydayIconTool" & " -l " & fullList & " -m " & monthSelAsText & " -d " & daySel & " -t " & folderSel
do shell script Tcommand

Yep, that worked :slight_smile:

Do you think it’s possible to do the same with the months then?

Of course it’s possible


property abbreviatedCountryList : {"en", "fr", "de"}
property countryList : {"English", "French", "German"}
property monthList : {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
property dayList : {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}

set folderSel to quoted form of POSIX path of (choose folder with prompt "Choose destination folder")

set monthSel to (choose from list monthList with prompt "Choose Month:")
if monthSel is false then return
set monthIndex to indexOfObjectInList(item 1 of monthSel, monthList)
set monthSelAsText to text -2 thru -1 of ("0" & monthIndex)

set daySel to (choose from list dayList with prompt "Choose Day:")
if daySel is false then return
set daySel to item 1 of daySel

set countries to {}
set countrySel to (choose from list countryList with prompt "Choose Country:" with multiple selections allowed)
if countrySel is false then return
repeat with anItem in countrySel
	set theIndex to indexOfObjectInList(contents of anItem, countryList)
	set end of countries to item theIndex of abbreviatedCountryList
end repeat
set {TID, text item delimiters} to {text item delimiters, ","}
set countries to countries as text
set text item delimiters to TID

set Tcommand to quoted form of "/Applications/Everyday Icon.app/Contents/Resources/EverydayIconTool" & " -l " & countries & " -m " & monthSelAsText & " -d " & daySel & " -t " & folderSel
do shell script Tcommand


on indexOfObjectInList(theObject, theList)
	repeat with i from 1 to (count theList)
		if theObject is equal to item i of theList then return i
	end repeat
end indexOfObjectInList

Fantastic, that works, thank you :slight_smile:

Last enhancement, I’m trying to resize all the images inside the folderSel (and subfolders), to add after “do shell script Tcommand” (?), I’ve tried this but doesn’t seem to work…

set folderSel to (choose folder with prompt "Pick the folder containing the images to process:") as string
tell application "System Events"
	set these_files to every file of folder folderSel whose name does not start with "." and (file type is "TIFF" or file type is "JPEG" or name extension is "tiff" or name extension is "tif" or name extension is "jpeg" or name extension is "jpg" or name extension is "png" or name extension is "PNG")
end tell
set imgSize to display dialog "Choose Size:" default answer ""

repeat with i from 1 to the count of these_files
	set this_file to (item i of these_files as alias)
	tell application "Image Events"
		set this_file to open these_files
		scale this_file to size imgSize
		save this_file in these_files
		close this_file
	end tell
end repeat

there are a few syntax errors in your script,
this is a different approach using Spotlight to filter the images in the specified folder (and subfolders)


set sourceFolder to quoted form of POSIX path of (choose folder with prompt "Pick the folder containing the images to process:")
set allImages to paragraphs of (do shell script "mdfind -onlyin " & sourceFolder & space & quoted form of "kMDItemContentTypeTree == '*public.image*'")

repeat
	set imageSize to text returned of (display dialog "Choose Size:" default answer "")
	try
		set imageSize to imageSize as integer
		exit repeat
	on error
		display dialog "Please enter an integer value" buttons {"Cancel", "Try Again"}
	end try
end repeat

launch application "Image Events"
repeat with anImage in allImages
	tell application "Image Events"
		try
			set currentImage to open anImage
			scale currentImage to size imageSize
			save currentImage with icon
			close currentImage
		on error
			try
				close currentImage
			end try
		end try
	end tell
end repeat


Oh that’s great, I’ve tried to avoid asking for the folder twice and replaced this:

set sourceFolder to quoted form of POSIX path of (choose folder with prompt "Pick the folder containing the images to process:")

with this

set sourceFolder to folderSel

but it doesn’t seem to be working and picking up all the images, hmmm, should it be equivalent?