How to open .rdp file in applescript

Discussion in 'Mac Programming' started by doynton, Nov 21, 2014.

  1. doynton macrumors 6502

    Joined:
    Oct 19, 2014
    #1
    I'd like to include launching Microsoft Remote Desktop and connecting to a specific defined session using applescript. I have exported the .rdp and double clicking on it works.

    How can I do this?

    I've tried
    Code:
    set VB_Guest to "Windows"
    set rdp to VB_Guest & ".rdp"
    set VB_rdp to quoted form of rdp
    
    tell application "Microsoft Remote Desktop"
    	open VB_rdp
    end tell
    
    which fails with "the URL is not valid"

    and
    Code:
    set VB_Guest to "Windows"
    set rdp to VB_Guest & ".rdp"
    set VB_rdp to quoted form of rdp
    
    tell application "Finder"
    	open VB_rdp
    end tell
    
    which fails with "Finder got an error: Handler can't handle objects of this class"

    Is this possible?
     
  2. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #2
    It looks a bit like you're using guess work as to what commands to use. Have you had a look at the Microsoft Remote Desktop scripting dictionary? That's probably the best place to start. You may find that it's not scriptable at all (I'm not familiar with it, I'm afraid), or you might find the right commands to use.

    If it's not scriptable then you may have some luck with UI scripting, although that's a bit clunky in my experience.
     
  3. kryten2, Nov 21, 2014
    Last edited: Nov 21, 2014

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #3
    You can try :

    Code:
    do shell script "open /POSIX path/to/your/Windows.rdp"
    Or

    Code:
    tell application "Finder" to open file HFS path to your Windows.rdp
    (*
    Specifying Paths
    You can create alias objects and file objects by supplying a name specifier, where the name is the path to an item in the file system.
    
    For alias and file specifiers, the path is an HFS path, which takes the form "disk:item:subitem:subsubitem:...:item". For example, "Hard_Disk:Applications:Mail.app" is the HFS path to the Mail application, assuming your boot drive is named "Hard_Disk".
    
    HFS paths with a leading colon, such as ":folder:file", are resolved relative to the HFS working directory. However, their use is discouraged, because the location of the HFS working directory is unspecified, and there is no way to control it from AppleScript.
    
    For POSIX file specifiers, the path is a POSIX path, which takes the form "/item/subitem/subsubitem/.../item". The disk name is not required for the boot disk. For example, "/Applications/Mail.app" is the POSIX path to the Mail application. You can see the POSIX path of an item in Finder in the "Where" field of its Get Info window. Despite the name, POSIX file specifiers may refer to folders or disks. Use of "~" to specify a home directory is not supported.
    
    POSIX paths without a leading slash, such as "folder/file", are resolved relative to the POSIX working directory. This is supported, but only is useful for scripts run from the shell—the working directory is the current directory in the shell. The location of the POSIX working directory for applications is unspecified.
    *)
    -- or
    tell application "Finder" to open file HFS path to your Windows.rdp using application file "Microsoft Remote Desktop.app" of folder "Applications" of startup disk
    Info : https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/open.1.html
     
  4. doynton, Nov 21, 2014
    Last edited: Nov 21, 2014

    doynton thread starter macrumors 6502

    Joined:
    Oct 19, 2014
    #4
    Yes I am - it is my first script.

    Thanks. I made it like this and it starts the .rdp from my apps Resources directory and works perfectly.

    Code:
    set VB_Guest to "Windows"
    set p2m to (path to me)'s POSIX path
    set VB_rdp to quoted form of (p2m & "Contents/Resources/" & VB_Guest & ".rdp")
    do shell script ("open " & VB_rdp) 
     

Share This Page