I’m trying to add a single entry to a .plist file, but can’t work out how.
I presume I’d have to read in all the existing Data, and add the entry, but as the existing data is at root level, how do I add and resave it, please?
on saveTheGeneralData()
try
set p to 0
set thePPath to POSIX path of (((my mailManagerDesktopFolderPath) & " General Data.plist") as text) as text
set theFlag to true
tell application "Finder"
if not (exists file (my mailManagerDesktopFolderPath & " General Data.plist" as text)) then set theFlag to false
end tell
if theFlag then
set myDict to current application's NSDictionary's dictionaryWithContentsOfFile:(thePPath) # POsIX path
end if
# How do I add this to myDict?
set myOldMonday to current application's NSDictionary's dictionaryWithDictionary:{thePreviousMondayKey:thePreviousMonday}
set p to 7
myDict's writeToFile:thePPath atomically:true
on error errmsg number errNum
tell application "System Events" to display dialog "OAS's saveTheGeneralData " & errmsg & " p = " & p as text giving up after 40
my setEMsgs:{errNum, "mainMessagesView", "saveTheGeneralData Error " & errmsg as text, "Error Message Orange", true, "Cochin Bold", "14"}
end try
end saveTheGeneralData
on openTheGeneralData()
try
set thePPath to POSIX path of (((my mailManagerDesktopFolderPath) & " General Data.plist") as text)
set theFlag to true
tell application "Finder"
if not (exists file (my mailManagerDesktopFolderPath & " General Data.plist" as text)) then set theFlag to false
end tell
if theFlag then
set nowreadList to current application's NSDictionary's dictionaryWithContentsOfFile:(thePPath) # POsIX path
try
set my thePreviousMonday to nowreadList's thePreviousMondayKey
on error
my setUpMondays()
set my thePreviousMonday to (my theCurrentMonday) - days * 7
end try
end if
on error errmsg
tell application "System Events" to display dialog "openTheGeneralData " & errmsg as text giving up after 40
end try
end openTheGeneralData