Plist changes?

How can i create script that grabs front most applications plist, then user changes preference(s) in that application and that changes plist then script grabs plist again and shows what preference(s) was changed and how?

Result:

SendFormat=Plain > HTML

Hi cirno,

You can read the plist with the unix ‘defaults’ command.

gl,

Hi Cirno,

my idea for your problem is to read the user defaults and redirect the output to two temp files - one before and one after - and compare those files using the shell command ‘diff’.

‘before’ script:

set tempFile to (POSIX path of (path to temporary items)) & "tmp_oldDefaults.plist"
tell application "System Events" to set infoPlist to ((application file of (first application process whose frontmost is true) as string) & "Contents:Info.plist")
set bundleId to (do shell script "cat " & quoted form of (POSIX path of infoPlist) & " | grep -A1 CFBundleIdentifier | tail -n1 | sed 's/[ ,	]*<\\/*string>//g'")
do shell script "defaults read " & bundleId & " > " & quoted form of tempFile

‘after’ script:

set tempFile to (POSIX path of (path to temporary items)) & "tmp_oldDefaults.plist"
set tempFile2 to (POSIX path of (path to temporary items)) & "tmp_newDefaults.plist"

tell application "System Events" to set infoPlist to ((application file of (first application process whose frontmost is true) as string) & "Contents:Info.plist")
set bundleId to (do shell script "cat " & quoted form of (POSIX path of infoPlist) & " | grep -A1 CFBundleIdentifier | tail -n1 | sed 's/[ ,	]*<\\/*string>//g'")
do shell script "defaults read " & bundleId & " > " & quoted form of tempFile2
try
	do shell script "diff " & quoted form of tempFile & space & quoted form of tempFile2
	display dialog "no changes"
on error errMsg
	display dialog "changes: " & return  & errMsg
end try

Notes:

  • I am not sure - there might be an easier (AppleScript) way to get the Bundle Identifier of the application - but I currently can’t remember/don’t know how.
  • The output of diff is not very user friendly - you should probably better add some code to parse and format this.
  • You know, that many (most) applications don’t write their user defaults instantly after the user has changed them. So in most cases you will have to quit and restart the application to find the differences.

D.

Stupid me - of course there is … :wink:

tell application "System Events" to set bundleId to bundle identifier of (info for (get application file of (first application process whose frontmost is true)))