ard 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 018c90a83bd82b0cfb541e0cdab3d287d807dbea
4
+ data.tar.gz: 2322d7c3644c9e167e01a695390dce7e987093bf
5
+ SHA512:
6
+ metadata.gz: 7b44dc43e55bf1de992ce6b092160cc0383a98f1694fb6b32c1d702f2a210176d10e2e4ce7ad0fda5637ca4049d983f36d95446186ef6da5ed7f7f21e76132a1
7
+ data.tar.gz: 3640475e93a17917689a85df343661a28791d5dd8d6c77bef07dd872bbe45158645b2338819ae0e79563fd9a83060559ed161d8648757d3eb3e030487b4afa97
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ard.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Nic Scott
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,146 @@
1
+ # ARD
2
+
3
+ A gem to help create and organize commands in Apple Remote Desktop
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ARD'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ARD
20
+
21
+ ## License
22
+
23
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
24
+
25
+ ## Usage
26
+
27
+
28
+ #### This script assume a couple of things:
29
+ * you have Apple Remote Installed on the local machine
30
+ * you run this script in the user account that uses Apple Remote Desktop
31
+ * for clarity and to avoid name collisions, all folders and commands you create should have unique names otherwise you can receive errors when trying to delete or move folders or commands
32
+ * it assumes you already have a file at ~/Library/Containers/com.apple.RemoteDesktop/Data/Library/Application Support/Remote Desktop/Presets/UnixCommandTask.plist, if you don’t open Apple Remote Desktop, click on “Unix” and save anything as your first command .. this auto generates the UnixCommandTask.plist file
33
+
34
+
35
+ <img src="https://i1.wp.com/redlinetech.files.wordpress.com/2017/06/ard-compare-e1498534221453.png">
36
+
37
+
38
+ ## Examples: ..
39
+ See [this blog post](https://redlinetech.wordpress.com/2017/05/17/organizing-commands-in-apple-remote-desktop-with-the-help-of-ruby/)
40
+
41
+
42
+ #### Print a list of command options:
43
+
44
+ ```ruby
45
+ puts ARD.list_options
46
+ ```
47
+ This will return:
48
+ > - create_command
49
+ > - create_folder
50
+ > - create_spacer
51
+ > - delete_command
52
+ > - delete_folder
53
+ > - folder_index
54
+ > - list_folders
55
+ > - move_command
56
+ > - move_folder
57
+ > - options
58
+ > - rename_command
59
+ > - rename_folder
60
+
61
+
62
+ #### Print existing commands and folders:
63
+ ```ruby
64
+ puts.ARD.list_folders
65
+ ```
66
+ returns any existing single commands or folders in ARD
67
+
68
+ ---
69
+
70
+ #### Create a new empty folder
71
+ argument is ("new_folder_name")
72
+ ```ruby
73
+ ARD.create_empty_folder("folder1")
74
+ ```
75
+
76
+ ---
77
+ #### Get the physical location of a folder:
78
+ ``` ruby
79
+ puts ARD.folder_index("folder1")
80
+ ```
81
+ returns the physical position of folder "folder1" as an integer
82
+
83
+ ---
84
+
85
+ #### Move existing command into folder:
86
+ arguments are ("commandname", "folder to move to")
87
+ ```ruby
88
+ ARD.move_command("Test Command", "Folder 1")
89
+ ```
90
+
91
+ ---
92
+
93
+
94
+ #### Move position of existing folder:
95
+ arguments are (original_position, new_position)
96
+ ```ruby
97
+ ARD.move_folder(1, 0)
98
+ ```
99
+
100
+ ---
101
+
102
+ #### Rename an existing folder:
103
+ arguments are (oldname, newname)
104
+ ```ruby
105
+ ARD.rename_folder("folder1", "folder0")
106
+ ```
107
+ ---
108
+
109
+ #### Rename an existing command:
110
+ arguments are (folder_name, orignialcommandname, newcommandname)
111
+ ```ruby
112
+ ARD.rename_command("folder0", "command2", "command1")
113
+ ```
114
+ ---
115
+
116
+ #### Create a visual space by using ----
117
+ arguments is physical location you want to create the spacer
118
+ ```ruby
119
+ ARD.create_spacer(1)
120
+ ```
121
+ ---
122
+
123
+ #### Rename an existing folder:
124
+ arguments are (oldname, newname)
125
+ ```ruby
126
+ ARD.rename_folder("folder1", "folder0")
127
+ ```
128
+ ---
129
+ #### Rename a command:
130
+ arguments are ("folder_name", "orignialcommandname", "newcommandname")
131
+ ```ruby
132
+ ARD.rename_command("Admin Commands", "list of users", "all users")
133
+ ```
134
+ ---
135
+ #### Delete a command:
136
+ arguments are ("folder_name", "command_name")
137
+ ```ruby
138
+ ARD.delete_command("folder2", "command1")
139
+ ```
140
+ ---
141
+
142
+ #### Delete an existing folder
143
+ arguments are ("foldername")
144
+ ```ruby
145
+ ARD.delete_folder("folder2")
146
+ ```
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ard/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ard"
8
+ spec.version = Ard::VERSION
9
+ spec.authors = ["Nic Scott"]
10
+ spec.email = ["nls.inbox@gmail.com"]
11
+
12
+ spec.summary = "A gem to help create and organize commands in Apple Remote Desktop "
13
+ spec.homepage = "https://github.com/nlscott/panes"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.15"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+ spec.add_development_dependency "CFPropertyList", "~> 2.0"
27
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ard"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,181 @@
1
+ require "ard/version"
2
+
3
+
4
+ require 'cfpropertylist'
5
+ require 'etc'
6
+
7
+ module ARD
8
+
9
+ CURRENTUSER=Etc.getlogin
10
+ PLISTFILE="/Users/#{CURRENTUSER}/Library/Containers/com.apple.RemoteDesktop/Data/Library/Application Support/Remote Desktop/Presets/UnixCommandTask.plist"
11
+ @plist = CFPropertyList::List.new(:file => "#{PLISTFILE}")
12
+ @results = CFPropertyList.native_types(@plist.value)
13
+
14
+ class Command
15
+ attr_reader :foldername, :commandname, :outputmode, :script, :user, :userselect
16
+
17
+ def initialize(foldername, commandname, outputmode, script, user, userselect)
18
+ @foldername = foldername
19
+ @commandname = commandname
20
+ @outputmode = outputmode
21
+ @script = script
22
+ @user = user
23
+ @userselect = userselect
24
+ end
25
+ end
26
+
27
+ #========================================================
28
+ # Methods
29
+
30
+ #print folder names
31
+ def self.list_folders
32
+ folders=[]
33
+ for x in @results
34
+ folders.push(x['name'])
35
+ end
36
+ return folders
37
+ end
38
+
39
+ #find index of folder
40
+ def self.folder_index(folder)
41
+ indexnumber=nil
42
+ for x in @results
43
+ if x['name'] == folder
44
+ indexnumber = @results.index(x)
45
+ end
46
+ end
47
+ if indexnumber.nil?
48
+ return "Folder does not exist"
49
+ else
50
+ return indexnumber
51
+ end
52
+ end
53
+
54
+ #add new folder with command
55
+ def self.create_folder(command)
56
+ data3=Hash.new
57
+ data3['name']="#{command.foldername}"
58
+ data3['state']=[data4=Hash.new]
59
+ data3['state'][0]={"name" => "#{command.commandname}", 'state' => Hash.new}
60
+ data3['state'][0]['state']['outputMode']= command.outputmode
61
+ data3['state'][0]['state']['script']= "#{command.script}"
62
+ data3['state'][0]['state']['user']= "#{command.user}"
63
+ data3['state'][0]['state']['userSelect']= command.userselect
64
+ @results.push(data3)
65
+ @plist.value = CFPropertyList.guess(@results)
66
+ @plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
67
+ end
68
+
69
+ def self.create_command(command)
70
+ indexnumber=folder_index(command.foldername).to_i
71
+ data = Hash.new
72
+ data2 = Hash.new
73
+ data2["outputMode"]= command.outputmode
74
+ data2["script"]= "#{command.script}"
75
+ data2["user"]= "#{command.user}"
76
+ data2["userSelect"]= command.userselect
77
+ data['name'] = "#{command.commandname}"
78
+ data['state'] = data2
79
+ @results[indexnumber]['state'].push(data)
80
+ @plist.value = CFPropertyList.guess(@results)
81
+ @plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
82
+ end
83
+
84
+ #create a spacer
85
+ def self.create_spacer(position)
86
+ position=position.to_i
87
+ data3=Hash.new
88
+ data3['name']="- - - - - - - - - - -"
89
+ @results.push(data3)
90
+ indexnumber = folder_index("- - - - - - - - - - -")
91
+ puts "index is #{indexnumber}"
92
+ @results.insert(position, @results.delete_at(indexnumber.to_i))
93
+ @plist.value = CFPropertyList.guess(@results)
94
+ @plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
95
+ end
96
+
97
+ #move an exisiting folders poistion
98
+ def self.move_folder(originialposition, newposition)
99
+ newposition=newposition.to_i
100
+ originialposition=originialposition.to_i
101
+ @results.insert(newposition, @results.delete_at(originialposition))
102
+ @plist.value = CFPropertyList.guess(@results)
103
+ @plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
104
+ end
105
+
106
+ #delete an existing folder
107
+ def self.delete_folder(folder)
108
+ indexnumber = folder_index("#{folder}")
109
+ indexnumber = indexnumber.to_i
110
+ @results.delete(@results[indexnumber])
111
+ @plist.value = CFPropertyList.guess(@results)
112
+ @plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
113
+ end
114
+
115
+ #rename an exisiting folder
116
+ def self.rename_folder(oldname, newname)
117
+ indexnumber = folder_index("#{oldname}")
118
+ indexnumber = indexnumber.to_i
119
+ @results[indexnumber]['name'] = newname
120
+ @plist.value = CFPropertyList.guess(@results)
121
+ @plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
122
+ end
123
+
124
+ #delete an exisiting command
125
+ def self.delete_command(folder_name, command_name)
126
+ indexnumber = folder_index("#{folder_name}")
127
+ indexnumber = indexnumber.to_i
128
+
129
+ command_indexnumber=nil
130
+ for x in @results[indexnumber]['state']
131
+ if x['name'] == "#{command_name}"
132
+ command_indexnumber = @results[indexnumber]['state'].index(x)
133
+ end
134
+ end
135
+
136
+ @results[indexnumber]['state'].delete(@results[indexnumber]['state'][command_indexnumber.to_i])
137
+ @plist.value = CFPropertyList.guess(@results)
138
+ @plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
139
+ end
140
+
141
+ #rename an exisiting command
142
+ def self.rename_command(folder_name, orignialcommandname, newcommandname)
143
+ indexnumber = folder_index("#{folder_name}")
144
+ indexnumber = indexnumber.to_i
145
+
146
+ command_indexnumber=nil
147
+ for x in @results[indexnumber]['state']
148
+ if x['name'] == "#{orignialcommandname}"
149
+ command_indexnumber = @results[indexnumber]['state'].index(x)
150
+ end
151
+ end
152
+
153
+ @results[indexnumber]['state'][command_indexnumber]['name'] = "#{newcommandname}"
154
+ @plist.value = CFPropertyList.guess(@results)
155
+ @plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
156
+ end
157
+
158
+ def self.options
159
+ puts ARD.methods(false).sort
160
+ end
161
+
162
+ def self.move_command(command, move_to_folder)
163
+ @results[ARD.folder_index(move_to_folder)]["state"] << @results[ARD.folder_index(command)]
164
+ @plist.value = CFPropertyList.guess(@results)
165
+ @plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
166
+ ARD.delete_folder(command)
167
+ end
168
+
169
+ def self.create_empty_folder(new_folder_name)
170
+ indexnumber = @results.count
171
+ indexnumber = indexnumber.to_i
172
+ data3=Hash.new
173
+ data3['name']="#{new_folder_name}"
174
+ @results.push(data3)
175
+ state = Array.new
176
+ @results[indexnumber]["state"] = state
177
+ @plist.value = CFPropertyList.guess(@results)
178
+ @plist.save("#{PLISTFILE}", CFPropertyList::List::FORMAT_XML)
179
+ end
180
+
181
+ end
@@ -0,0 +1,3 @@
1
+ module Ard
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nic Scott
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: CFPropertyList
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ description:
70
+ email:
71
+ - nls.inbox@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - ard.gemspec
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/ard.rb
86
+ - lib/ard/version.rb
87
+ homepage: https://github.com/nlscott/panes
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.5.1
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: A gem to help create and organize commands in Apple Remote Desktop
111
+ test_files: []