Module: Panes

Defined in:
lib/panes.rb,
lib/panes/version.rb

Constant Summary collapse

PATHTOPLIST =

Variables

"/System/Library/PreferencePanes"
PreferencePanes =
Dir.entries("#{PATHTOPLIST}")
VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.CFBundleIdentifierObject

print CFBundleIdentifier for each item in /System/Library/PreferencePanes folder



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/panes.rb', line 25

def self.CFBundleIdentifier
	list_of_panes=[]
	PreferencePanes.each do |prePane|
		if !prePane.start_with?(".")
			list_of_panes << prePane
		end
	end

	final_list=[]
	list_of_panes.each do |prePane|
		plist = CFPropertyList::List.new(:file => "#{PATHTOPLIST}/#{prePane}/Contents/Info.plist")
		results=CFPropertyList.native_types(plist.value)
		final_list << results["CFBundleIdentifier"]
	end
	return final_list
end

.CreateProfileObject

creates an empty com.apple.systempreferences in tmp folder



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/panes.rb', line 64

def self.CreateProfile
	profile = "/Library/preferences/com.apple.systempreferences.plist"
	new_profile = File.open(profile, "w")
	new_profile.puts '<?xml version="1.0" encoding="UTF-8"?>
	<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
	<plist version="1.0">
	<dict>
		<key>DisabledPreferencePanes</key>
		<array>
		</array>
	</dict>
	</plist>
	'
	new_profile.close
	FileUtils.chmod(0644,"#{profile}")
    FileUtils.chown 'root', 'wheel', "#{profile}"
end

.Disable(*prefs) ⇒ Object

to restrict access to a preference pane, put the CFBundleIdentifier as the argument example is Panes.Disable(“com.apple.preference.network”)



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/panes.rb', line 84

def self.Disable(*prefs)

	if File.file?("/Library/preferences/com.apple.systempreferences.plist")
		preference_panes_to_disable =[]

		prefs.each do |x|
			preference_panes_to_disable << x
		end

		plist = CFPropertyList::List.new(:file => "/Library/preferences/com.apple.systempreferences.plist")
		results=CFPropertyList.native_types(plist.value)

		results["DisabledPreferencePanes"].each do |x|
			preference_panes_to_disable << x
		end

		preference_panes_to_disable.each do |x|
			indexnumber = preference_panes_to_disable.index(x)
			results["DisabledPreferencePanes"][indexnumber] = "#{x}"
		end

		plist.value = CFPropertyList.guess(results)
		plist.save("/Library/preferences/com.apple.systempreferences.plist", CFPropertyList::List::FORMAT_BINARY)
	else
		Panes.CreateProfile
		preference_panes_to_disable =[]

		prefs.each do |x|
			preference_panes_to_disable << x
		end

		plist = CFPropertyList::List.new(:file => "/Library/preferences/com.apple.systempreferences.plist")
		results=CFPropertyList.native_types(plist.value)

		results["DisabledPreferencePanes"].each do |x|
			preference_panes_to_disable << x
		end

		preference_panes_to_disable.each do |x|
			indexnumber = preference_panes_to_disable.index(x)
			results["DisabledPreferencePanes"][indexnumber] = "#{x}"
		end

		plist.value = CFPropertyList.guess(results)
		plist.save("/Library/preferences/com.apple.systempreferences.plist", CFPropertyList::List::FORMAT_BINARY)

	end
	command="sudo killall cfprefsd"
	system(command)
end

.Enable(*prefs) ⇒ Object

to remove a restriction, put the CFBundleIdentifier as the argument



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/panes.rb', line 136

def self.Enable(*prefs)
	if File.file?("/Library/preferences/com.apple.systempreferences.plist")
		plist = CFPropertyList::List.new(:file => "/Library/preferences/com.apple.systempreferences.plist")
		results=CFPropertyList.native_types(plist.value)
		prefs.each do |check_a|
			results["DisabledPreferencePanes"].each do |check_b|
				if check_a == check_b 
					results["DisabledPreferencePanes"].delete(check_a)
				end
			end
		end
		plist.value = CFPropertyList.guess(results)
		plist.save("/Library/preferences/com.apple.systempreferences.plist", CFPropertyList::List::FORMAT_BINARY)
		command="sudo killall cfprefsd"
		system(command)
	else
		puts "Error: no plist. Try running 'sudo killall cfprefsd' from the terminal"
	end
end

.ListObject

Print .prePanes in /System/Library/PreferencePanes folder



14
15
16
17
18
19
20
21
22
# File 'lib/panes.rb', line 14

def self.List
	list_of_panes=[]
	PreferencePanes.each do |prePane|
		if !prePane.start_with?(".")
			list_of_panes << prePane
		end
	end
	puts list_of_panes
end

.OptionalCFBundleIdentifierObject

print CFBundleIdentifier for items installed by the user, typical installs would be flash or java



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/panes.rb', line 43

def self.OptionalCFBundleIdentifier
	optionalpanes=Dir.entries("/Library/PreferencePanes")

	list_of_panes=[]
	optionalpanes.each do |prePane|
		if !prePane.start_with?(".")
			list_of_panes << prePane
		end
	end

	final_list=[]
	list_of_panes.each do |prePane|
		plist = CFPropertyList::List.new(:file => "/Library/PreferencePanes/#{prePane}/Contents/Info.plist")
		results=CFPropertyList.native_types(plist.value)
		final_list << results["CFBundleIdentifier"]
	end
	return final_list
end

.OptionsObject

to print all the availbe options to use with the Panes command



166
167
168
# File 'lib/panes.rb', line 166

def self.Options
	puts (Panes.methods - Object.methods).sort
end

.ResetObject

reset all disable panes



158
159
160
161
162
163
# File 'lib/panes.rb', line 158

def self.Reset
	command="sudo rm -rf /Library/Preferences/com.apple.systempreferences.plist"
	system(command)
	cfprefsd="sudo killall cfprefsd"
	system(cfprefsd)
end