Skip to content

Instantly share code, notes, and snippets.

@username0x0a
Created June 19, 2023 19:27
Show Gist options
  • Save username0x0a/cbf02dcf5325090b12189dda80f414bf to your computer and use it in GitHub Desktop.
Save username0x0a/cbf02dcf5325090b12189dda80f414bf to your computer and use it in GitHub Desktop.
Simple Ruby script that allows you to watch Property list changes (f.e. in `~/Library/Preferences`) that you can catch, export to a dot file & synchronise between multiple machines. πŸ‘
#!/usr/bin/env ruby
# Prerequisities:
# - brew install fswawtch
# - gem install diffy
# Usage:
# cd ~/Library/Preferences; ruby system_settings_differ.rb
require 'pp'
require 'pty'
require 'diffy'
plist_files = { }
files = `find "$PWD" -name '*.plist'`.split "\n"
files.each{|file|
plist_files[file] = `plutil -p #{file}`
}
cmd = "fswatch ."
filtered = [
'ContextStoreAgent.plist',
'com.apple.xpc.activity2.plist',
'com.apple.knowledge-agent.plist',
]
begin
PTY.spawn(cmd) do |stdin, stdout, pid|
begin
stdin.each {|line|
line = line.strip
next if plist_files[line] == nil
new_content = `plutil -p #{line}`
diff = Diffy::Diff.new(plist_files[line], new_content, :context => 1).to_s
next if diff.length < 5
next if filtered.include? File.basename line
puts line + ":"
puts diff
plist_files[line] = new_content
}
rescue Errno::EIO
puts "Errno:EIO error, but this probably just means " +
"that the process has finished giving output"
end
end
rescue PTY::ChildExited
puts "The child process exited!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment