I use the following code snip to check that the necessary columns are present in the outline:
-- check that script is applicable to the OO file should contain the required columns
if title of every column does not contain {"Number", "Issues", "IOM Build", "Status", "Type", "Resolution", "Priority", "Created"} then
display dialog "This outline does not have the correct columns to run this script ! " buttons "Cancel" default button 1
end if
The works but it requires that the columns are entered in the code in the same order as they appear in the outline. Does anyone know of a way to get around this limitation?
I think that the issue is that your list is being tested as a monolithic container (i.e. including order). If you break it down into the elements of the list and test for each one individually, it should allow you to move them around.
Hope this helps.
Ken
tell application "OmniOutliner"
set d1 to document 1
set listCol to index of last column of d1 -- how many columns in document
-- actual columns in document
set colNameList to {}
repeat with c from 2 to listCol
copy title of column c of d1 to end of colNameList
end repeat
end tell
--required columns in document
set needList to {"Number", "Issues", "IOM Build", "Status", "Type", "Resolution", "Priority", "Created"}
repeat with nTitle in needList
if colNameList does not contain nTitle then
display dialog "This outline does not have the correct columns to run this script ! " buttons "Cancel" default button 1
end if
end repeat
colNameList -- Visually provide actual column titles
My pleasure. Not sure what you mean by display but you if you list the missing columns then you can add new columns based on that list. If you just want to know what’s missing, then remove the last repeat loop (and change the notification verbiage).
tell application "OmniOutliner"
set d1 to document 1
set listCol to index of last column of d1 -- how many columns in document
-- actual columns in document
set colNameList to {}
repeat with c from 2 to listCol
copy title of column c of d1 to end of colNameList
end repeat
--required columns in document
set needList to {"Number", "Issues", "IOM Build", "Status", "Type", "Resolution", "Priority", "Created"}
--list of missing columns
set missList to {}
repeat with nTitle in needList
if colNameList does not contain nTitle then
set missList to missList & nTitle
end if
end repeat
--Status report
if missList is not null then
set AppleScript's text item delimiters to {", "}
set missString to missList as string
end if
if missString is not "" then
display notification missString with title "These missing column(s) were added: "
else
display notification with title "No columns are missing"
end if
--add missing columns
repeat with addC in missList
make new column in d1 with properties {name:addC}
end repeat
set AppleScript's text item delimiters to {""}
end tell