Skip to content

Instantly share code, notes, and snippets.

@jasiek
Created April 23, 2016 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasiek/5b36d556baa4fc457169edfe5754db89 to your computer and use it in GitHub Desktop.
Save jasiek/5b36d556baa4fc457169edfe5754db89 to your computer and use it in GitHub Desktop.
Remove a .pkg (package) and its contents from MacOS X.
require 'fileutils'
package = ARGV.shift
info = `pkgutil --pkg-info #{package}`.split("\n")
exit if info.empty?
files = `pkgutil --files #{package}`.split("\n")
volume = nil
location = nil
directory = nil
info.each do |line|
/^volume: (.*)/.match(line) do |m|
volume = m[1]
end
/^location: (.*)/.match(line) do |m|
location = m[1]
end
end
directory = File.join(volume, location)
Dir.chdir(directory) do
FileUtils.rm_rf(files)
files.each do |file|
puts "File still exists: #{file}" if File.exists?(file)
end
end
`pkgutil --forget #{package}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment