I’ve written before how Shane's eBook method of saving to a .plist no longer works with some data, specifically listed data from Array Controllers, in High Sierra, but with the latest iterations of current Sierra, they’ve stopped working too!!!
The code below, which reads data from 4 controllers, works on my first pass setting it up, with default data, and the Array Controller lists set as simply {}, but on the second pass, when the Array Controllers actually contain data, and they save as a .plist file, the list becomes unopenable after just the first write.
on saveTheGeneralData()
# Set up Emails
try
say 100
set emailText1Array to table1ArrayController's arrangedObjects() as list
say 101
on error errmsg
set emailText1Array to {}
my displayError("saveTheGeneralData 1 " & errmsg as text)
end try
try
set emailText2Array to table2ArrayController's arrangedObjects() as list
on error errmsg
set emailText2Array to {}
my displayError("saveTheGeneralData 2 " & errmsg as text)
end try
try
set emailText3Array to table3ArrayController's arrangedObjects() as list
on error errmsg
set emailText3Array to {}
my displayError("saveTheGeneralData 3 " & errmsg as text)
end try
#
try
set (my lastReceivedEmailsList) to emailListArrayController's arrangedObjects() as list
on error errmsg
set lastReceivedemailsListList to {}
my displayError("saveTheGeneralData 4 " & errmsg as text)
end try
try
set thePPath to POSIX path of ((path to desktop as text) & "Mail Manager Folder:General Data.plist") as text
on error errmsg number errnum
tell application "System Events" to display dialog "Setting thePPath " & errmsg
end try
try
set numbersDict to current application's NSDictionary's dictionaryWithDictionary:{sendNumbersChartAlsoKey:sendNumbersChartAlso, sendNumbersChartOnlyKey:sendNumbersChartOnly, numbersGraphStoreEachNumbersFileKey:numbersGraphStoreEachNumbersFile, numbersGraphPreviousDaysPermanentKey:numbersGraphPreviousDaysPermanent, numbersGraphPreviousWeeksPermanentKey:numbersGraphPreviousWeeksPermanent, numbersGraphPreviousMonthsPermanentKey:numbersGraphPreviousMonthsPermanent, numbersGraphLastYearsPermanentKey:numbersGraphLastYearsPermanent, theNumbersGraphTypeKey:theNumbersGraphType}
on error errmsg number errnum
my displayError("saveTheGeneralData set numbersDict " & errmsg as text)
end try
tell application id "com.apple.systemevents"
set plistParentRecord to make new property list item with properties {kind:record} as record
set propertyListFile to make new property list file with properties {contents:plistParentRecord, name:thePPath}
#
# Actually Arrays
#
tell property list items of propertyListFile
try
make new property list item at end with properties {kind:list, name:"emailText1Key", value:{emailText1Array}} — <<< ALWAYS FAILS HERE WHEN ACTUALLY WRITING DATA, Says ‘1’, but never ‘2’ once written.
say 1
end try
try
make new property list item at end with properties {kind:list, name:"emailText2Key", value:emailText2Array}
say 2
end try
try
# make new property list item at end with properties {kind:record, name:"emailText3Key", value:{emailText3Array}}
say 3
end try
try
make new property list item at end with properties {kind:list, name:"lastReceivedEmailsListKey", value:lastReceivedEmailsList}
say 3.1
end try
try
make new property list item at end with properties {kind:list, name:"numbersDictKey", value:numbersDict}
say 4
end try
try
make new property list item at end with properties {kind:list, name:"eMailAddressesListButtonKey", value:eMailAddressesListButton}
say 4.01
end try
try
make new property list item at end with properties {kind:list, name:"hourlyReportsKey", value:hourlyReports}
say 4.1
end try
try
make new property list item at end with properties {kind:list, name:"salesAddressKeeperStoreKey", value:salesAddressKeeperStore}
say 4.3
end try
try
make new property list item at end with properties {kind:list, name:"theSmallPaperListsKey", value:theSmallPaperList}
say 4.4
end try
try
make new property list item at end with properties {kind:list, name:"theLargePaperListKey", value:theLargePaperList}
say 4.5
end try
try
make new property list item at end with properties {kind:list, name:"eMailAddressesListKey", value:eMailAddressesList}
say 4.6
end try
try
say 5
make new property list item at end with properties {kind:string, name:"mailAddressesMainErrorKey", value:mailAddressesMainError}
make new property list item at end with properties {kind:string, name:"theBusinessNameKey", value:theBusinessName}
on error errmsg
tell application "System Events" to display dialog errmsg
end try
say 6
make new property list item at end with properties {kind:number, name:"emailsMaxRetrievableKey", value:emailsMaxRetrievable}
# ETC.
say 7
make new property list item at end with properties {kind:date, name:"theLastMidnightCheckerStoreNSDateKey", value:theLastMidnightCheckerStoreNSDate}
# ETC.
say 9
make new property list item at end with properties {kind:boolean, name:"serverBackupStateKey", value:serverBackupState}
# ETC.
say 10
end tell
end tell
end saveTheGeneralData