rubyxcodebugsnag

Ruby shell script read from XCode plist


I am trying to read a plist value using a /usr/bin/ruby script. How can I do this?

Bugsnag API script

fork do
  Process.setsid
  STDIN.reopen("/dev/null")
  STDOUT.reopen("/dev/null", "a")
  STDERR.reopen("/dev/null", "a")

  require 'shellwords'

  BUGSNAG_API_KEY=$(defaults read "$FRAMEWORK/APIKeys.plist" bugsnag) // Convert this to ruby

  Dir["#{ENV["DWARF_DSYM_FOLDER_PATH"]}/*/Contents/Resources/DWARF/*"].each do |dsym|
    system("curl --http1.1 -F apiKey={BUGSNAG_API_KEY} -F dsym=@#{Shellwords.escape(dsym)} -F projectRoot=#{Shellwords.escape(ENV["PROJECT_DIR"])} https://upload.bugsnag.com/")
  end
end

Solution

  • BUGSNAG_API_KEY=$(defaults read "$FRAMEWORK/APIKeys.plist" bugsnag)
    

    Assuming this is sh, it's running a command and capturing its output in a string. In Ruby you use backticks to do that

    BUGSNAG_API_KEY = `defaults read #{ENV['FRAMEWORK']}/APIKeys.plist bugsnag`
    

    The only thing I had to change was using ENV to access environment variables instead of sh's $ syntax.