Class: SimCtl::DeviceSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/simctl/device_settings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ DeviceSettings

Returns a new instance of DeviceSettings.



7
8
9
# File 'lib/simctl/device_settings.rb', line 7

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/simctl/device_settings.rb', line 5

def path
  @path
end

Instance Method Details

#disable_keyboard_helpersvoid

This method returns an undefined value.

Disables the keyboard helpers



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/simctl/device_settings.rb', line 14

def disable_keyboard_helpers
  edit_plist(path.preferences_plist) do |plist|
    plist['DidShowContinuousPathIntroduction'] = true
    %w[
      KeyboardAllowPaddle
      KeyboardAssistant
      KeyboardAutocapitalization
      KeyboardAutocorrection
      KeyboardCapsLock
      KeyboardCheckSpelling
      KeyboardPeriodShortcut
      KeyboardPrediction
      KeyboardShowPredictionBar
    ].each do |key|
      plist[key] = false
    end
  end
end

#edit_plist(path) {|content| ... } ⇒ Object

Yields:

  • (content)


43
44
45
46
47
48
49
# File 'lib/simctl/device_settings.rb', line 43

def edit_plist(path)
  plist = File.exist?(path) ? CFPropertyList::List.new(file: path) : CFPropertyList::List.new
  content = CFPropertyList.native_types(plist.value) || {}
  yield content
  plist.value = CFPropertyList.guess(content)
  plist.save(path, CFPropertyList::List::FORMAT_BINARY)
end

#set_language(language) ⇒ void

This method returns an undefined value.

Sets the device language



54
55
56
57
58
59
60
# File 'lib/simctl/device_settings.rb', line 54

def set_language(language)
  edit_plist(path.global_preferences_plist) do |plist|
    key = 'AppleLanguages'
    plist[key] = [] unless plist.key?(key)
    plist[key].unshift(language).uniq!
  end
end

#set_locale(locale) ⇒ void

This method returns an undefined value.

Sets the device locale



65
66
67
68
69
# File 'lib/simctl/device_settings.rb', line 65

def set_locale(locale)
  edit_plist(path.global_preferences_plist) do |plist|
    plist['AppleLocale'] = locale
  end
end

#update_hardware_keyboard(enabled) ⇒ vod

Updates hardware keyboard settings

Parameters:

  • enabled

    value to replace

Returns:

  • (vod)


37
38
39
40
41
# File 'lib/simctl/device_settings.rb', line 37

def update_hardware_keyboard(enabled)
  edit_plist(path.preferences_plist) do |plist|
    plist['AutomaticMinimizationEnabled'] = enabled
  end
end