20

I haven't been able to find any documentation that would indicate this is possible, but is there any way to pass the hostname you'd like to connect to as a command-line argument to Microsoft's Remote Desktop Connection for Mac?

Some background info for those interested:

I'm a systems administrator, and I'm in the process of moving to a MacBook Air as my primary work computer from a Windows 7 laptop. I frequently use Remote Desktop Client to connect to servers, and in Windows, I use Launchy as my keyboard launcher. I've assigned "rdp" as a keyword so when I invoke Launchy, type "rdp {tab} servername" it passes the text after the tab key as the hostname to mstsc.exe (i.e., mstsc.exe /v:servername). This results in the remote desktop client opening a session to the hostname specified.

  • 2
    Sadly, no there is no command line access or AppleScript access to Remote Desktop Client. I've asked the CoRD developer if he'd consider adding it to CoRD though. And there's my plug for a better client than MS' RDP client: cord.sourceforge.net. :) – Ian C. Jun 27 '12 at 21:40
  • @Ian C., I'd used CoRD in the past, on my personal MacBook... it feels like it's been a few years. Wasn't really satisfied with it compared to the stability and more "polished" look of Microsoft's client. I actually just downloaded it again, because I noticed in one of their screenshots, there was a mention of handling rdp:// links. This does exactly what I'm looking for, so thanks for pointing me back towards CoRD! I was able to set up a "shell script" extension in Alfred that executes "open rdp://{query}". Cheers! – billc Jun 27 '12 at 22:20
  • Oh wow. I didn't even notice it handled rdp:// links. That's awesome. I'll make my comment an answer. :) – Ian C. Jun 27 '12 at 22:33
11

There is no command line access for the Microsoft Remote Desktop Client. But the free and most excellent CoRD remote desktop client does handle rdp:// links which would let you call it from a launcher of your choice or even via open on the command line.

The CoRD documentation on github lays out how you can use URL encoded parameters to open full-configured RDP sessions.

rdp:// URL syntax

CoRD handles rdp:// URLs, which you can use from many places inside OS X. Unfortunately, there is no way to extend Finder's "Connect to Server" dialog, which supports launching VNC URLs, so we can't launch CoRD from there. If Apple changes this (or if anybody is aware of a way to extend it) we would love to hear about it.

Saved Servers

If you want to use rdp:// urls with existing saved servers, you can (as of 0.5.3)! Just use the label in place of a hostname:

open rdp://label

New Servers

From a shell (using Terminal):

open rdp://hostname

Additional parameters can be used to start a fully-configured session via the URL:

open rdp://[username[:password]@]hostname[:port][/domain][?parameters]

The following parameters can be set for the session via a query string (as of 0.5.2):

  • screenDepth ### [8|16|24|32]
  • screenWidth <width in pixels>
  • screenHeight <height in pixels>
  • consoleSession ### [true|false|yes|no]
  • fullscreen ### [true|false|yes|no]
  • windowDrags ### [true|false|yes|no]
  • drawDesktop ### [true|false|yes|no]
  • windowAnimation ### [true|false|yes|no]
  • themes ### [true|false|yes|no]
  • fontSmoothing ### [true|false|yes|no]
  • forwardDisks ### [true|false|yes|no]
  • forwardPrinters ### [true|false|yes|no]
  • forwardAudio ### [0|1|2]
    • 0 - Forward Audio to the Local Machine (Currently not used since CoRD doesn't present audio)
    • 1 - Leave Audio at the Remote Machine
    • 2 - Disable Audio at both Machines

Example

open rdp://jsmith:securePassword@hostname.bigco.com/BigCoDomain?screendepth###24\&consoleSession###true\&themes###false\&screenWidth###1280\&screenHeight###800

Note:

When using ampersands (&) from the command line, they have to be escaped with a backslash (). Colons (:) can be used in place of ampersands for the same effect, without needing to be escaped.

Passwords with any special characters in them, @, :, &, etc need to be encoded according to the URL Encoding Format

Command Line Use

CoRD supports the following command line options: -host -port -u -d -p -a [8|16|24|32] set screen depth -width set screen resolution width -height set screen resolution height

Example

/Applications/CoRD.app/Contents/MacOS/CoRD -host example.com -port 3389 -u username

Caveats

Launching CoRD from the command line this way causes a fresh instance of CoRD to be opened. One symptom of this is multiple Dock icons. This overrides or decreases the effectiveness of many of CoRD strong points, including unified sessions, etc. For that reason, we recommend using the open command, and rdp:// URLs to launch sessions.

enter image description here

  • 1
    Too funny! I was answering my own question as you answered it as well. Thanks again for your help! – billc Jun 27 '12 at 22:39
  • According to CoRD GitHub page, this project is no longer being maintained as of August 16, 2015. – kenorb Apr 6 '18 at 11:51
  • Pity. It was good. – Ian C. Apr 7 '18 at 4:13
  • This answer is outdated: newer versions of Microsoft Remote Desktop for Mac support rdp:// links (though using a different scheme). See Jack Douglas' answer. – chrstphrchvz Apr 9 at 18:05
7

I don't love CoRD. It works, but it seems to flake out periodically. I made my own CLI script for Microsoft RDP. I created a sed+open bash script to make it possible to pass 2 arguments to Microsoft Remote Desktop Client. I can pass a host name, and I can throw a switch to connect to the console of Server 2003 hosts.

I know this could be taken further. For Example:

  • My bash script will not work with spaces in the paths or file names :)
  • I imagine any of the XML data in the .RDP file could be modified with sed.
  • I included a number of variations of a switch for connecting to the console because I'm old and can never remember which one I like. I bet that bash scripting has a more elegant solution than I use.

Here is how I did it:

  1. Create a Microsoft RDP template profile with all of your preferred settings. Name it 'template.rdp'. Make it connect to a fake server. I used a server name 'zzxyzyz'. This gets used in the 'sed' command as the string to search for and replace with a real server name.
  2. Create a bash script to copy the template.rdp to a temp.rdp, then sed the temp.rdp with the desired host name that gets passed in when invoking the script. I named my bash script 'rdp.sh'.
  3. Modify your '~/.bash_profile' to include an alias to 'rdp.sh'
  4. Make the bash script executable: chmod +x rdp.sh
  5. Bob's yer uncle

Contents of my bash script:

    #! /bin/bash
rdpTemplateFile='/Users/levi/Dropbox/RDC_Connections/RDS/template.rdp'
rdpTempRDP='/Users/levi/Dropbox/RDC_Connections/RDS/t.rdp'
rdpRunCommand="/Applications/Remote Desktop Connection.app/Contents/MacOS/Remote Desktop Connection"
rdpHost=${1}

if [ "${2}" = "/console" ] ; then
    rdpHost="${rdpHost} /console";
    echo "rdpHost is: " ${rdpHost}
fi

if [ "${2}" = "-console" ] ; then
    rdpHost="${rdpHost} /console";
    echo "rdpHost is: " ${rdpHost}
fi

if [ "${2}" = "-admin" ] ; then
    rdpHost="${rdpHost} /console";
    echo "rdpHost is: " ${rdpHost}
fi

cp -f ${rdpTemplateFile} ${rdpTempRDP}

sed -i '' "s|zzxyzyz|${rdpHost}|g" ${rdpTempRDP}

open -na "${rdpRunCommand}" --args ${rdpTempRDP}

Alias added to .bash_profile
(This assumes my rdp.sh script file is in my home directory, ~/ )

alias rdp=~/rdp.sh

Make the script executable:

sudo chmod +x rdp.sh

Run the script:
Here is an example that includes the console switch. I left a debugging line in the script that shows what is going to be sed'd into the t.rdp file.

LeviMAC>rdp MyServer -console
rdpHost is:  MyServer /console
[~/]
LeviMAC>
  • I was able to get this concept to work, but only after some modification. The command I used to start RDP was open -na "/Applications/Microsoft Remote Desktop.app/Contents/MacOS/Microsoft Remote Desktop" path/to/profile.rdp – Terrabits Jun 21 '17 at 23:10
6

I don't know when this changed, but the Microsoft Remote Desktop Client does handle rdp:// links now:

Microsoft Remote Desktop uses the URI scheme rdp://query_string to store pre-configured attribute settings that are used when launching the client. The query strings represent a single or set of RDP attributes provided in the URL. The RDP attributes are separated by the ampersand symbol (&).

For example, when connecting to a PC, the string is:

rdp://full%20address=s:mypc:3389&audiomode=i:2&disable%20themes=i:1

All the attributes are documented on the Remote Desktop Client URI Scheme Support TechNet page.

  • I would LOVE to se some sample URLs. I have my local port 3389 forwarded to a Windows machine and I connect as user "et" using the official Microsoft Remote Desktop app. But, I cannot construct a URL that doesn't give an error. – Bruno Bronosky Nov 22 '16 at 5:37
  • Try using 127.0.0.2 instead of localhost? – Jack Douglas Nov 22 '16 at 9:38
  • 1
    Have any ideas about how to store/pass passwords? – Bruno Bronosky Nov 22 '16 at 18:20
  • 1
    Saving the password in the Microsoft Remote Desktop (for Mac) app is what I currently do. However, my goal is to launch a connection to a new IP:Port via the command line after opening that port via ssh tunnel. I'm just trying to improve my script which currently ends with "Now change the host of the saved connection to 10.10.1.23:5589 and connect" – Bruno Bronosky Nov 23 '16 at 0:01
  • 1
    Please let me know if you find a way :) – Jack Douglas Nov 24 '16 at 9:12
1

Well, after consulting my Microsoft TAM, I've found that there is no way to pass a hostname to the Microsoft client via the command line.

CoRD, on the other hand, can actually do what I'd like by handling rdp:// links. After installing CoRD, if you type

open rdp://servername

in Terminal or iTerm2, it will open a session to the host servername within CoRD.

I use Alfred (http://www.alfredapp.com/) as my "Launchy" alternative on Mac, having just discovered it after being a longtime user of Quicksilver. I bought the Powerpack for Alfred, which allows you to use a number of extensions, one of which give it the ability to launch shell scripts. So I created a shell script extension, assigned the keyword rdp, set it to "required parameter", and set the script to:

open rdp://{query}

This allows me to invoke alfred, and type rdp {tab} servername {return} to open a Remote Desktop Connection session to the remote server.

0

The script above doesn't work with the latest "Microsoft Remote Desktop". Referencing the application with a variable was problematic so I hard coded the path (which is different from the original example). I also needed to remove the '--args' parameter and it started to work.

open -na /Applications/Microsoft\ Remote\ Desktop.app/Contents/MacOS/Microsoft\ Remote\ Desktop ${rdpTempRDP}
0

So this is mostly to flesh out other answers and avoid scripting hacks:

(TL;DR: may have not been true before, but Microsoft's RDP now handles .rdp files automatically with open)

I have a lot of profiles already stored in the RDP GUI. (BTW, the plist is ~/Library/Containers/com.microsoft.rdc.mac/Data/Library/Preferences/com.microsoft.rdc.mac.plist, as always plutil -convert xml1 xyz.list for human viewing)

(Further reference: https://macmule.com/2013/10/22/how-to-create-a-microsoft-remote-desktop-8-connection/)

To make it commandlineable:

  1. Select the profile in the GUI
  2. File -> Export creates the .rdp file, noting that it will lack password info
  3. (Study the .rdp to see how the parameters correspond to the manual rdp:// syntax)
  4. Simply openfilename.rdp from command line
-1

I think it would be just as easy to make a template for each server you want to connect to, as well as one with an empty server field for those "once in a lifetime" connections. I just pop them in a folder and either name or number them to get the order right. Drag the folder to the dock and I have a spot I can click to get a quick list of the rdp templates which I can then just single-click to connect. Or I can Command+Space and type in the name of the file and press enter to run it. OR YOU CAN TYPEY TYPEY TYPEY TYPE and install all kinds of management apps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .