Skip to content

Instantly share code, notes, and snippets.

@rdark
Last active May 16, 2016 10:14
Show Gist options
  • Save rdark/34014fc16c37ff2eccd9ca814d845cc3 to your computer and use it in GitHub Desktop.
Save rdark/34014fc16c37ff2eccd9ca814d845cc3 to your computer and use it in GitHub Desktop.
OSX Hardware Info
#!/usr/bin/env ruby
#
# Pull basic hardware info from system profiler and copy to clipboard
#
require 'open3'
hardware = {
model_identifer: 'Model Identifier',
model_name: 'Model Name',
sys_serial: 'Serial Number \(system\)',
hw_uuid: 'Hardware UUID',
cpu_name: 'Processor Name',
cpu_speed: 'Processor Speed',
cpu_cores: 'Total Number of Cores'
}
captured_stdout = ''
Open3.popen3('system_profiler', 'SPHardwareDataType') do |stdin , stdout, stderr, thread|
captured_stdout = stdout.read
end
result = {}
hardware.each_key do |k|
begin
result[k] = captured_stdout[/.*#{hardware[k]}: (.*)\n/,1].chomp
rescue NoMethodError
result[k] = "Unknown"
end
end
tsv = result.each_key.map {|m| "#{result[m]}" }.join("\t")
IO.popen('pbcopy', 'w') {|p| p << tsv }
puts "The system data has been copied to your clipboard."
puts "Now paste this into the sheet (⌘ + v)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment