I’m thinking this is simple but I’m don’t know the best practice to handle this. I’ve got a list of font names that are “bad”. I want to make an association of a certain “bad” font and replace it with a “good” font. It’s two lists that I want to make a one-to-one association.
What is best practice to do this? Here’s an attempt
set listOne to {"Helvetica", "Symbol", "Snell Roundhand"}
set listTwo to {"Arial", "Times", "Zapf"}
set propertyList to ("font used: "Arial")
repeat with thisName in listTwo
if thisName is in propertyList then
set propertyList to ("font used: "Helvetica") -- & item x of listOne STUCK here
end if
end repeat
return propertyList
This is a silly example, but of course Indesign returns a record. If I find the “bad” font in the record, I want to change it to its corresponding “good” font. I understand I may not change the record, but I still want to make the basic one-to-one association without having to do ordinals?
Is that the way I have to do it? thanx, sam
I do not have indesign so a little hard to get what you after.
I am not sure if this is what you after doing.
set listOne to {"Helvetica", "Symbol", "Snell Roundhand"}
set listTwo to {"Arial", "Times", "Zapf"}
set propertyList to ("Times")
(* using "i from 1 to number of items in" allows you to get the record number
of item of listTwo that is being processed.
And use that number to get the corrosponding record number for listOne
if there is a match .
*)
repeat with i from 1 to number of items in listTwo
set thisName to item i of listTwo
if thisName is in propertyList then
set propertyList to item i of listOne
end if
end repeat
propertyList --> "Symbol"
Or
set listOne to {"Helvetica", "Symbol", "Snell Roundhand", "copper"}
set listTwo to {"Arial", "Times", "Zapf", "dingbats"}
set propertyList to {"Times", "dingbats"}
set propertyList2 to {}
(* using "i from 1 to number of items in" allows you to get the record number
of item of listTwo that is being processed.
And use that number to get the corrosponding record number for listOne
if there is a match .
*)
repeat with i from 1 to number of items in listTwo
set thisName to item i of listTwo
if thisName is in propertyList then
set propertyList2 to propertyList2 & item i of listOne
else
set propertyList2 to propertyList2 & thisName
end if
end repeat
propertyList2 --> {"Arial", "Symbol", "Zapf", "copper"}
set listOne to {"Helvetica", "Symbol", "Snell Roundhand", "copper"}
set listTwo to {"Arial", "Times", "Zapf", "dingbats"}
return matchedItem(listOne, listTwo, "Symbol")
-- "Times"
on matchedItem(aList, bList, aItem)
copy "" to end of bList
repeat with anItem in aList
if anItem as text = aItem then exit repeat
set bList to rest of bList
end repeat
return item 1 of bList
end matchedItem
Yes, all good responses. I’m trying to find a general solution for this type of problem. It appears that I need to use the ordinals. To do that, the two lists must be static, which is suitable in this situation.
Sorry if I’m being thick?
But I’m still a bit confused as to what you are after.
In my examples. a bad font in a list gets replaced with a good font from the corresponding item (counted) in the other list.
{“1b”,“2b”,“3b”} badlist
{“1g”,“2g”,“3g”} goodlist
{,“2b” } record from indesign
{“2g”} new record after change
editor do you want some thing like this.
set listOne to {"Helvetica", "Symbol", "Snell Roundhand"}
set listTwo to {"Arial", "Times", "Zapf"}
set propertyList to {"Times", "Zapf"}
set new_list to {}
repeat with i from 1 to number of items in listTwo
set thisName to item i of listTwo
if thisName is in propertyList then
set theCompar to item i of listTwo & "->" & item i of listOne
copy theCompar to end of new_list
end if
end repeat
new_list --> {"Times->Symbol", "Zapf->Snell Roundhand"}
you keep mentioning ordinals, but I am confused as to why.
Can you give a better example of what you are after. ( Not a script) showing what you start with and what you want to end up with.
It would be simpler (and easier to maintain) if you had just one list, containing good-font/bad-font pairs. Either a list of lists or a list of records. From your example, your ‘list2’ appears to be the “bad” list, so the list of lists approach would be:
set fontPairs to {{"Arial", "Helvetica"}, {"Times", "Symbol"}, {"Zapf", "Snell Roundhand"}}
set propertyList to ("font used: \"Arial\"")
repeat with thisPair in fontPairs
if (propertyList contains beginning of thisPair) then
set propertyList to ("font used: \"" & end of thisPair & "\"")
exit repeat
end if
end repeat
return propertyList
Using a list of records:
set fontPairs to {{|bad font|:"Arial", |good font|:"Helvetica"}, {|bad font|:"Times", |good font|:"Symbol"}, {|bad font|:"Zapf", |good font|:"Snell Roundhand"}}
set propertyList to ("font used: \"Arial\"")
repeat with thisPair in fontPairs
if (propertyList contains thisPair's |bad font|) then
set propertyList to ("font used: \"" & thisPair's |good font| & "\"")
exit repeat
end if
end repeat
return propertyList
Wonderful! Both Nigel and mike got what I was trying to get at. I was trying to avoid knowing which pair was the first, seventeenth, etc as it got larger. I just wanted to build a master list that had the pairs already built as we handle more documents.
I’m grateful for these solutions and will learn from these, thanx again, sam