Module: MacAdmin::Common
Overview
Common
-
module comtaining classes and methods common to macadmin
Defined Under Namespace
Classes: UUID
Constant Summary collapse
- MAC_OS_X_PRODUCT_VERSION =
Mac OS X major version number
`/usr/bin/sw_vers`.split("\n")[1].split("\t").last.to_f
Instance Method Summary collapse
-
#get_primary_mac_address ⇒ Object
Get the primary ethernet’s MAC address - returns String.
-
#load_plist(file) ⇒ Object
Load a PropertyList file - convenience method - single parameter is a path to the ProperyList file - returns a Hash is if can parse the file - returns nil if it cannot parse the file.
-
#restart_directoryservice(wait = 10) ⇒ Object
(also: #restart_opendirectoryd)
Restart the local directory service daemon - single param wait (Integer) measured in seconds - default wait is 10 seconds.
Instance Method Details
#get_primary_mac_address ⇒ Object
Get the primary ethernet’s MAC address
-
returns String
47 48 49 50 |
# File 'lib/macadmin/common.rb', line 47 def get_primary_mac_address raw = %x{/sbin/ifconfig en0} raw.split("\n").grep(/ether/).first.split.last end |
#load_plist(file) ⇒ Object
Load a PropertyList file
-
convenience method
-
single parameter is a path to the ProperyList file
-
returns a Hash is if can parse the file
-
returns nil if it cannot parse the file
57 58 59 60 61 |
# File 'lib/macadmin/common.rb', line 57 def load_plist(file) return nil unless File.exists? file plist = CFPropertyList::List.new(:file => file) CFPropertyList.native_types(plist.value) end |
#restart_directoryservice(wait = 10) ⇒ Object Also known as: restart_opendirectoryd
Restart the local directory service daemon
-
single param wait (Integer) measured in seconds
-
default wait is 10 seconds
66 67 68 69 70 71 72 73 |
# File 'lib/macadmin/common.rb', line 66 def restart_directoryservice(wait=10) if MAC_OS_X_PRODUCT_VERSION > 10.6 system('/usr/bin/killall opendirectoryd') else system('/usr/bin/killall DirectoryService') end sleep wait end |