Read value from preference file

Sometimes as a developer you want to know what is in your com.microsoft.Excel.plist file.

The example below will only work when you use the new AppleScriptTask function in Excel 2016 and higher. Below you will find the Appelscript that you must save into a script file named ReadPlistValue and copy it in the correct location, and the VBA macro that you can use to run the script.

Follow the steps from this page to get it working : How to use AppleScriptTask in Mac Office

The Applescript


--Ron de Bruin, www.rondebruin.nl
--2-Nov-2020
--Applescripts for reading values in the Excel plist file

on GetPlistValue(paramstring)
set {fieldvalue1, fieldValue2} to SplitString(paramstring, ";")
tell application "System Events"
set PLRoot to property list file (fieldvalue1)
return value of property list item fieldValue2 of PLRoot
end tell
end GetPlistValue

on SplitString(TheBigString, fieldSeparator)
tell AppleScript
set oldTID to text item delimiters
set text item delimiters to fieldSeparator
set theItems to text items of TheBigString
set text item delimiters to oldTID
end tell
return theItems
end SplitString

The VBA macro


Sub ReadPlistValue()
Dim PlistPathString As String
Dim PlistValueString As String
Dim CompleteString As String
Dim RunMyScript As String

'This point to the Excel plist file, no need to change it
PlistPathString = MacScript("return (path to Home folder as text)") & "Library:Preferences:com.microsoft.Excel.plist"
'Fill in the value you want to read
PlistValueString = "SessionLongBuildNumber"

On Error Resume Next
CompleteString = PlistPathString & ";" & PlistValueString
RunMyScript = AppleScriptTask("ReadPlistValue.scpt", "GetPlistValue", CompleteString)
On Error GoTo 0

MsgBox PlistValueString & " = " & RunMyScript
End Sub

See also this page if you want to save/read information from your own files in a plist file.
SaveSetting, GetSetting and DeleteSetting on Mac
7-March-2021
Web design by Will Woodgate