If you have purchased the latest MacHeist nano bundle, you might have noticed that there is no option this time to export as an AppShelf file. I felt a little guilty spamming my twitter followers to get my three free bonus apps (Airburst Extreme, Tracks, and Burning Monkey Solitaire), so to atone, I’m sharing a script that will translate your reciept into an AppShelf import file. Just save your receipt page from the browser, then pass the filename to this script as an argument:
RUBYOPT=rubygems ruby generate-appshelf.import.rb MacHeist-Serial.htmlThe script will create an import file named “nano-bundle-3.appshelf” in your current directory. Enjoy!
#!/usr/bin/env ruby -wKU | |
require 'nokogiri' | |
require 'time' | |
receipt_file = ARGV.shift || '' | |
if receipt_file.empty? | |
puts "please point me to your receipt file" | |
exit 1 | |
end | |
doc = Nokogiri.HTML(IO.read(receipt_file)) | |
def write_keypair(filehandle, name, value, type='string') | |
filehandle.puts "\t\t<key>#{name}</key>" | |
filehandle.puts "\t\t<#{type}>#{value}</#{type}>" | |
end | |
purchasedDate = Time.now.utc.iso8601 | |
File.open("nano-bundle-3.appshelf", "w") do |out| | |
out.puts %Q{<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<array> | |
} | |
(doc / "div.license").each do |license| | |
link = (license / "h4 a").first | |
next unless link | |
out.puts "\t<dict>" | |
write_keypair(out, :appName, link.text) | |
write_keypair(out, :details, '') | |
# directoryName | |
write_keypair(out, :homepage, link.attribute('href')) | |
write_keypair(out, :price, '$19.95 (Bundle)') | |
write_keypair(out, :purchasedDate, purchasedDate, 'date') | |
# purchasedVersion | |
labels = (license / "dl dt").map{|e| e.text } | |
values = (license / "dl dd").map{|e| e.text } | |
registrationData = Hash[*labels.zip(values).flatten] | |
write_keypair(out, :registrationEmail, registrationData['Email:']) | |
write_keypair(out, :registrationName, registrationData['Name:']) | |
write_keypair(out, :registrationSerialKey, registrationData['Serial:']) | |
write_keypair(out, :wherePurchased, 'http://www.macheist.com') | |
out.puts "\t</dict>" | |
end | |
out.puts %Q{</array>\n</plist>} | |
end |