Does anyone know how to get the list of SDEF enumerations for an application using regular AppleScript, or do I have to write a script to read and parse the SDEF myself?
I think, you have to parse and access SDEF by yourself.
Like this.
I wrote a much more simplified script (this sample is for application “Microsoft Word”)
It will bring back the enumeration list for “WdColorIndex”
set mySdef to (path to application "Microsoft Word" as text) & "Contents:Resources:Word.sdef"
return getEnumerations("WdColorIndex", mySdef)
on getEnumerations(anItem, mySdef)
local i, myVals, aVal
tell application "System Events"
tell XML file mySdef
repeat with j from 1 to count XML elements of XML element "dictionary"
set myVals to value of XML attribute "name" of (XML elements of XML element j of XML element "dictionary" whose name is "enumeration")
if (count myVals) > 0 then
set i to my getIndexOfItemInList("WdColorIndex", myVals)
if i > 0 then
set myVals to value of XML attributes of XML elements of (XML element i of XML element j of XML element "dictionary" whose name is "enumeration")
repeat with aVal in myVals
set contents of aVal to item 1 of aVal
end repeat
return myVals
end if
end if
end repeat
end tell
end tell
end getEnumerations
on getIndexOfItemInList(theItem, theList)
script L
property aList : theList
end script
repeat with a from 1 to count of L's aList
if item a of L's aList is theItem then return a
end repeat
return 0
end getIndexOfItemInList
I made an even better script that also return the constants as actual constants
set myApp to "Microsoft Word"
set myEnumerations to getEnumerations(myApp)
set {hColors, hColorConstants} to getConstants("WdColorIndex", myApp)
on getConstants(anItem, appName)
local i, mySdef, myConstants, aVal, tid
set flag to false
set mySdef to ((path to application appName as text) & "Contents:Resources:")
tell application "System Events"
set mySdef to files of folder mySdef whose name extension is "sdef"
if (count mySdef) > 0 then
set mySdef to path of (item 1 of mySdef)
tell XML file mySdef
repeat with j from 1 to count XML elements of XML element "dictionary"
set myConstants to value of XML attribute "name" of (XML elements of XML element j of XML element "dictionary" whose name is "enumeration")
if (count myConstants) > 0 then
set i to my getIndexOfItemInList(anItem, myConstants)
if i > 0 then
set myConstants to value of XML attributes of XML elements of (XML element i of XML element j of XML element "dictionary" whose name is "enumeration")
repeat with aVal in myConstants
set contents of aVal to item 1 of aVal
end repeat
set tid to my text item delimiters
set my text item delimiters to ", "
set myScript to "tell application \"" & appName & "\" to return {" & (myConstants as text) & "}"
set my text item delimiters to tid
return {myConstants, run script myScript}
exit repeat
end if
end if
end repeat
end tell
end if
end tell
return {{}, {}}
end getConstants
on getEnumerations(appName)
local i, mySdef, myConstants, aVal
set flag to false
set mySdef to ((path to application appName as text) & "Contents:Resources:")
set myConstants to {}
tell application "System Events"
set mySdef to files of folder mySdef whose name extension is "sdef"
if (count mySdef) > 0 then
set mySdef to path of (item 1 of mySdef)
tell XML file mySdef
repeat with j from 1 to count XML elements of XML element "dictionary"
set myConstants to myConstants & value of XML attribute "name" of (XML elements of XML element j of XML element "dictionary" whose name is "enumeration")
end repeat
end tell
end if
end tell
return myConstants
end getEnumerations
on getIndexOfItemInList(theItem, theList)
script L
property aList : theList
end script
repeat with a from 1 to count of L's aList
if item a of L's aList is theItem then return a
end repeat
return 0
end getIndexOfItemInList