Created
October 17, 2014 16:31
-
-
Save nkammah/7d1de3e132d7061352a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
command :pget do |c| | |
c.syntax = 'ipa pget <key> [options]' | |
c.summary = 'Retrieve a value in a plist' | |
c.description = '' | |
c.option '-p', '--plist FILE', "plist file to update" | |
c.action do |args, options| | |
@key = args.count > 0 ? args[0] : 'CFBundleShortVersionString' | |
determine_plist! unless @plist = options.plist | |
say_error "Missing or unspecified .plist file" and abort unless @plist and File.exist?(@plist) | |
puts Shenzhen::PlistBuddy.print(@plist, @key) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private | |
def determine_plist! | |
plist = Dir["**/*-Info.plist"].reject {|p|p =~ /^Libraries\// || p =~ /^bin\//} | |
@plist ||= case plist.length | |
when 0 then nil | |
when 1 then plist.first | |
else | |
@plist = choose "Select a plist File:", *plist | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
command :pset do |c| | |
c.syntax = 'ipa pset <key> <value> [options]' | |
c.summary = 'Set the value in a plist' | |
c.description = '' | |
c.option '-p', '--plist FILE', "plist file to update" | |
c.action do |args, options| | |
say_error "Missing key and value" and abort unless args.count == 2 | |
key, value = args | |
determine_plist! unless @plist = options.plist | |
say_error "Missing or unspecified .plist file" and abort unless @plist and File.exist?(@plist) | |
value = Shenzhen::PlistBuddy.set(@plist, key, value) | |
say_error "Key '#{key}' not found in #{@plist}" and abort if value.nil? | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Shenzhen::PlistBuddy | |
class << self | |
def print(file, key) | |
output = `/usr/libexec/PlistBuddy -c "Print :#{key}" "#{file}" 2> /dev/null` | |
!output || output.empty? || /Does Not Exist/ === output ? nil : output.strip | |
end | |
def set(file, key, value) | |
output = `/usr/libexec/PlistBuddy -c "Set #{key} #{value}" "#{file}" 2>&1` | |
output == "" ? value : nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment