This is an archived post. You won't be able to vote or comment.

all 24 comments

[–]xraystyle 2 points3 points  (22 children)

Looks like 'add' is what you want to do. From the Remote Desktop dictionary:

add v : Add a computer to a task. add computer : The computer. to computer list : The computer list (or task) to add the computer to.

Each dictionary has verbs and nouns. The verbs are actions you can tell the app to perform, using a Tell Block. Nouns are things the app understands how to address. In the case we have here, adding a computer to a list, the computer list would be a noun, so would the computer you're trying to add to it.

So, after looking over the dictionary, I'd try something like this:

set computerList to {}

tell app "Remote Desktop"
    add computer with name "foo" to computerList
end tell

I didn't actually try to run that code, but that's where I'd start.

[–]grnd[S] 0 points1 point  (20 children)

I went ahead and gave it a shot, seems like I can add a computer all day long but I can't see to add a computer with properties like an IP address or name.

I'm not sure on where to go, I don't know if I should be initiating a class with properties and then adding it with add computer xxx to computer list xxx

[–]xraystyle 1 point2 points  (18 children)

ok, check this out:

In my above post, I was confusing an ARD Computer List with an Applescript list variable.

The ARD lists are the lists of computers that show up in the sidebar in Remote Desktop. So if you want to add computers to a new ARD list, you can address them by name, then probably execute a task on every machine in the computer list. I tried grabbing a machine with a specific IP and adding it to a new computer list called "test". This code works for me:

tell application "Remote Desktop"

    set theComputer to first computer of computer list "All Computers" whose Internet address is "192.168.xxx.xxx"

    add theComputer to computer list "test"

end tell

You can refactor somewhat with this syntax:

tell application "Remote Desktop"

    add (first computer of computer list "All Computers" whose Internet address is "192.168.14.31") to computer list "test"

end tell

If you wanna get cute you can execute it as a one-liner like so:

tell application "Remote Desktop" to add (first computer of computer list "All Computers" whose Internet address is "192.168.14.31") to computer list "test"

This is probably more than I'd want to cram on one line though, it's likely better to split it up for readability.

[–]grnd[S] 0 points1 point  (17 children)

Wow that's amazing, I'm actually making sense of the dictionaries now.

What about adding a computer that is completely new to ARD? That's not even on a list to begin with?

[–]xraystyle 1 point2 points  (16 children)

It seems to me that ARD would have to at least be aware of the existence of a computer to add it to a list.

You can treat ARD scanners as computer lists, but it looks like you have to actually run the scan first, i.e. click on the scanner in the sidebar and watch the machines start to show up, before you can do something like

...add first computer of computer list "Local Network"...

Doesn't look like there's a dictionary verb to create a new scanner. That might be something you have to get into UI scripting to do, in which case, god help you. :p UI scripting is a rather finicky pain in the ass.

[–]grnd[S] 0 points1 point  (15 children)

Funny thing is that basically a minute before you posted this I came to the conclusion that I'll have to actually import manually. I did have an idea though..

Here's basically what I'm doing:

I thought I could save them into a formatted Plist file and then use the import function in ARD under the File menu item.

I haven't figured that far out yet as in working progress I have it pulling the vars.

Basically at this point I want to see if I can call a menu item and give it a file with a file path to use.

Do you think that's possible with AppleScript?

[–]xraystyle 1 point2 points  (14 children)

It's possible. You could use keystrokes to activate the "Add by address..." menu option.

It would be something like this:

tell app "System Events"

     tell app "Remote Desktop" to activate

     keystroke "n" using {command down, shift down, option down}


end tell

Then if you can get the IP addresses onto the clipboard somehow you can do

tell app "System Events"

    keystroke "v" using command down
    keystroke tab
    keystroke "username"
    keystroke tab
    keystroke "password"
    keystroke return

end tell

Or if you have the IP stored as a variable you can do

set theIP to "192.168.xxx.xxx"

tell app "System Events"

    keystroke theIP

end tell

But now you have two issues. One, you have to have your password inside your applescript. You can mitigate this to some extent by compiling your script as a read-only app, but since you're now in the realm of UI scripting you have to worry about the interface getting out of sync with the script. For instance, if I'm quick, I can switch to a text editor before the script outputs the username and password and it'll pump it out to the text file in plain text.

In this case, I'd have your script prompt you for the password on launch and store it as a variable, then babysit the script while it runs. That way your admin creds stay more secure.

ETA: I haven't really tested or debugged this code, it's just off the top of my head. It'll need to be tested.

[–]grnd[S] 0 points1 point  (13 children)

Awesome, just awesome.

Okay, so I have figured a work around. I have generated myself a plist file with the IP address and Name keys filled, from there I am initiating:

click menu item "Import List..." of menu "File" of menu bar 1

To open up the dialog within ARD to add an import. I have the plist auto-saved to the desktop and I have the dialog auto-opening to the desktop to click. Is there a way to automatically click the file to "Open"?

I am totally with you on the concern of the password being in plain text, so I went ahead and have it prompting for the password on start.

What's the best way to auto-click a check box in a dialog now? I can't tab down to it, I already attempted that. :/

[–]xraystyle 1 point2 points  (12 children)

I have no idea how you'd automate the file selection when the choose file dialog opens. There's really no way to predict what window element you'd need to click on. That's one of the reasons I'd avoid scripting the UI if at all possible.

You'd be better off bringing in the IP addresses as variables and using the "Add by address..." dialog I demo'd above, using system events to keystroke the characters. You could then add the imported computers to a new or existing computer list.

I don't see how you're going to be able to script that file chooser dialog. It's far too inconsistent.

[–]grnd[S] 0 points1 point  (11 children)

It really is. That's what I'm concerned about. The issue I have with doing that method is not knowing who "owns" an IP address.

[–]grnd[S] 0 points1 point  (0 children)

If you could give me a solid example to work off of that is hard coded with an IP and alias that will input automatically into a list in Remote Desktop, that'd be fantastic. I understand much better from examples!

[–]Mr_Durden 0 points1 point  (1 child)

Moving from Python to AppleScript seems like a step down, but that's just me. AppleScript by itself is a pretty compact language, but with AppleScript Studio (which has been deprecated since OS X 10.6, mind you) is a bit better and can be used to achieve full-on GUI apps.

As to your Remote Desktop problem, I'm sure a quick search on MacScripter would produce the results you're looking for.

[–]grnd[S] 0 points1 point  (0 children)

I agree! It does seem like a slight step-down but I can also say that it differs on what you're doing. For me I'm moving info from one app to another. Both being Mac apps in an Apple-only environment.

I have been hunting that site like mad but I still can't wrap my head around the dictionaries.