Module: ARD

Defined in:
lib/ard.rb

Defined Under Namespace

Classes: Command

Constant Summary collapse

CURRENTUSER =
Etc.getlogin
PLISTFILE =
"/Users/#{CURRENTUSER}/Library/Containers/com.apple.RemoteDesktop/Data/Library/Application Support/Remote Desktop/Presets/UnixCommandTask.plist"

Class Method Summary collapse

Class Method Details

.create_command(command) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ard.rb', line 69

def self.create_command(command)
	indexnumber=folder_index(command.foldername).to_i
	data = Hash.new
	data2 = Hash.new
	data2["outputMode"]= command.outputmode
	data2["script"]= "#{command.script}"
	data2["user"]= "#{command.user}"
	data2["userSelect"]= command.userselect
	data['name'] = "#{command.commandname}"
	data['state'] = data2
	@results[indexnumber]['state'].push(data)
	@plist.value = CFPropertyList.guess(@results)
	@plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
end

.create_empty_folder(new_folder_name) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
# File 'lib/ard.rb', line 169

def self.create_empty_folder(new_folder_name)
	indexnumber = @results.count
	indexnumber = indexnumber.to_i
	data3=Hash.new
	data3['name']="#{new_folder_name}"
	@results.push(data3)
	state = Array.new
	@results[indexnumber]["state"] = state
	@plist.value = CFPropertyList.guess(@results)
	@plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
end

.create_folder(command) ⇒ Object

add new folder with command



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ard.rb', line 55

def self.create_folder(command)
	data3=Hash.new
	data3['name']="#{command.foldername}"
	data3['state']=[data4=Hash.new]
	data3['state'][0]={"name" => "#{command.commandname}", 'state' => Hash.new}
	data3['state'][0]['state']['outputMode']= command.outputmode
	data3['state'][0]['state']['script']= "#{command.script}"
	data3['state'][0]['state']['user']= "#{command.user}"
	data3['state'][0]['state']['userSelect']= command.userselect
	@results.push(data3)
	@plist.value = CFPropertyList.guess(@results)
	@plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
end

.create_spacer(position) ⇒ Object

create a spacer



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ard.rb', line 85

def self.create_spacer(position)
	position=position.to_i
	data3=Hash.new
	data3['name']="- - - - - - - - - - -"
	@results.push(data3)
	indexnumber = folder_index("- - - - - - - - - - -")
	puts "index is #{indexnumber}"
	@results.insert(position, @results.delete_at(indexnumber.to_i))
	@plist.value = CFPropertyList.guess(@results)
	@plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
end

.delete_command(folder_name, command_name) ⇒ Object

delete an exisiting command



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/ard.rb', line 125

def self.delete_command(folder_name, command_name)
	indexnumber = folder_index("#{folder_name}")
	indexnumber = indexnumber.to_i

	command_indexnumber=nil
	for x in @results[indexnumber]['state']
		if x['name'] == "#{command_name}"
			command_indexnumber = @results[indexnumber]['state'].index(x)
		end
	end

	@results[indexnumber]['state'].delete(@results[indexnumber]['state'][command_indexnumber.to_i])
	@plist.value = CFPropertyList.guess(@results)
	@plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
end

.delete_folder(folder) ⇒ Object

delete an existing folder



107
108
109
110
111
112
113
# File 'lib/ard.rb', line 107

def self.delete_folder(folder)
	indexnumber = folder_index("#{folder}")
	indexnumber = indexnumber.to_i
	@results.delete(@results[indexnumber])
	@plist.value = CFPropertyList.guess(@results)
	@plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
end

.folder_index(folder) ⇒ Object

find index of folder



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ard.rb', line 40

def self.folder_index(folder)
	indexnumber=nil
	for x in @results
		if x['name'] == folder
			indexnumber = @results.index(x)
		end
	end
 	if indexnumber.nil?
		return "Folder does not exist"
	else
		return indexnumber
	end
end

.list_foldersObject

print folder names



31
32
33
34
35
36
37
# File 'lib/ard.rb', line 31

def self.list_folders
	folders=[]
	for x in @results
		 folders.push(x['name'])
	end
	return folders
end

.move_command(command, move_to_folder) ⇒ Object



162
163
164
165
166
167
# File 'lib/ard.rb', line 162

def self.move_command(command, move_to_folder)
	@results[ARD.folder_index(move_to_folder)]["state"] << @results[ARD.folder_index(command)]
	@plist.value = CFPropertyList.guess(@results)
	@plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
	ARD.delete_folder(command)
end

.move_folder(originialposition, newposition) ⇒ Object

move an exisiting folders poistion



98
99
100
101
102
103
104
# File 'lib/ard.rb', line 98

def self.move_folder(originialposition, newposition)
	newposition=newposition.to_i
	originialposition=originialposition.to_i
	@results.insert(newposition, @results.delete_at(originialposition))
	@plist.value = CFPropertyList.guess(@results)
	@plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
end

.optionsObject



158
159
160
# File 'lib/ard.rb', line 158

def self.options
	puts ARD.methods(false).sort
end

.rename_command(folder_name, orignialcommandname, newcommandname) ⇒ Object

rename an exisiting command



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ard.rb', line 142

def self.rename_command(folder_name, orignialcommandname, newcommandname)
	indexnumber = folder_index("#{folder_name}")
	indexnumber = indexnumber.to_i
	
	command_indexnumber=nil
	for x in @results[indexnumber]['state']
		if x['name'] == "#{orignialcommandname}"
			command_indexnumber = @results[indexnumber]['state'].index(x)
		end
	end		

	@results[indexnumber]['state'][command_indexnumber]['name'] = "#{newcommandname}"
	@plist.value = CFPropertyList.guess(@results)
	@plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
end

.rename_folder(oldname, newname) ⇒ Object

rename an exisiting folder



116
117
118
119
120
121
122
# File 'lib/ard.rb', line 116

def self.rename_folder(oldname, newname)
	indexnumber = folder_index("#{oldname}")
	indexnumber = indexnumber.to_i
	@results[indexnumber]['name'] = newname
	@plist.value = CFPropertyList.guess(@results)
	@plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
end