Organizing Unix Commands In Apple Remote Desktop

ARD_icon_3.png

Apple Remote Desktop (ARD) has always had a cool feature to run Unix commands on client machines. If you want to save those commands you have the option to create a “Template”.

This can be a huge time saver. When you first open ARD and click on the “Unix” button, then click on the “Templates” drop down menu in the upper right. You get the out-of-box, neat and clean, defaults. Nicely organized for you.

000

ARD defaults

But after time .. things can get unruly. It can look like this, or worse depending on how many commands you have saved.

001.png

unorganized list of commands

It would be nice if Apple provided a built-in way to create folders and organize commands. What’s that, an update to ARD that adds features … I know … crazy talk.

But you can edit the plist manually, create your own folders, and organize as you wish. So you end up with something a bit cleaner.

002.png

organized commands with custom folders


Starting With A Clean UnixCommandTask.plist

You can find the plist that holds the commands at:

"/Users/(username)/Library/Containers/com.apple.RemoteDesktop/Data/Library/Application Support/Remote Desktop/Presets"

Assuming you have ARD installed and use it. If you don’t have that file it means you haven’t saved any commands as a template. No worries, we’ll create the file.

I’m going to start with a clean “UnixCommandTask.plist” by renaming my original, “-old”. This way I preserve my already saved commands and if something goes wrong, I have a backup.

To create the plist, open ARD and click on the “Unix” command button. Type anything in the command field. Click the “User” button and add “root”, then click on “Template”. Choose “Save as Template” and when the name field pops up, type “test”.

Screen Shot 2017-03-13 at 9.47.22 AM.png

Screen Shot 2017-03-13 at 9.47.32 AM.png

Now you should have a new “UnixCommandTask.plist” in your “Presets” folder.

Screen Shot 2017-03-13 at 11.15.13 AM.pngOpen it in Xcode and it should look like this:

Screen Shot 2017-03-13 at 10.31.51 AM.png

You can do this with a text editor … it’s just XML, but because the structure is nested, it’s a bitter easier and cleaner to visualize in Xcode.

Click the triangle next to “Item 0”, which is just a dictionary, to expand and you’ll see two keys, “name” and “state”.

Screen Shot 2017-03-13 at 10.32.56 AM.png

Next to “name” you can see it’s a “string” named … “test”. The name we gave our test command. Open “state” and you’ll see the attributes that go with the command.

outputMode = (this is the checkbox "Command Results: Display all output")
script = (the actually field you enter the command)
user = (if you run commands as root you want to make sure this is set)
userSelect = (must be set to 1, with the above user key set to root. If it's 0 it defaults to current console user)
Screen Shot 2017-03-13 at 10.33.40 AM.png

If you don’t have all 4 fields inside state, you can click the + button to the right of state and manually create them


Creating a Folder

Now that you can see the structure, how do we create our own folder?

We make a simple change. Go back and select “Item 0” and copy it (command + c), and change the “name” key from “test” to “test folder”.

Screen Shot 2017-03-13 at 10.41.46 AM.png

Now delete the 4 items inside the “state” key and change “state” from “Dictionary” to “Array”.

Screen Shot 2017-03-13 at 10.43.24 AM.png

With the “state” key selected, paste (command + v) the original “Item 0” into “state”.

Screen Shot 2017-03-13 at 10.45.28 AM.png

Expand “Item 0” and you’ll see the original structure for our test command.

Screen Shot 2017-03-13 at 10.46.32 AM.png

 

Open ARD and you should now see a new folder named “test folder”, with a command named “test”.

Screen Shot 2017-03-13 at 10.47.16 AM.png

Now you have a way to create folders. To create another folder, you could just go back to “Item 0” under “Root” and copy it, select “Root” and paste it. Then you have two items. Expand “Item 1” and change the name from “test folder” to “test folder 2”.

Screen Shot 2017-03-13 at 10.52.41 AM.png

Open ARD and check the change.

Screen Shot 2017-03-13 at 10.53.01 AM.png


Create New Commands Inside Folders

To create a second command inside a custom folder, you would just expand the “state” field under the command name, copy “Item 0”, select “state” and paste, creating “Item 1”.

Screen Shot 2017-03-13 at 11.31.44 AM.png

Expand “Item 1”. Change the “name” field to “test command 2”. Expand “state” and select “script”. In the “value” field type or paste any command you want. For this example, I’ll type a simple command .. “ls -l”.

Screen Shot 2017-03-13 at 11.32.30 AM.png

One last check in ARD should show 2 commands in our second folder. Select “test command 2”, it populates the text field with the same command, “ls -l”, that I edited in Xcode.

Screen Shot 2017-03-13 at 11.35.13 AM.png


Wrap Up

Now you can get started organizing and editing your ARD commands. If you use ARD on multiple machines or have multiple Admins that you want to have to the same commands. Just copy the plist and drop it in the same folder on every machine.

In a future post, hopefully soon … I’ll post a ruby script that will automate this. It will handled the Dictionary and Array fields and make it easier to add commands or change existing commands.

 

 

 

 

 

 

 

 

Leave a comment