How can I use rb-appscript to drive Mac OS Finder's "Connect To Server" menu item

206 Views Asked by At

The end goal is to write an automated test in Ruby/Cucumber for connecting to a WebDAV server and testing authentication, CRUD and load/performance in Mac OS X.

I'm trying to simulate user behavior as much as possible which is why I'm looking at rb-appscript, but I'm open to other ideas.

I initially tried this:

app("Finder").open_location("http://example.com/dav")

but that just opens your default browser. I'm guessing open_location just uses Mac OS' default app based on protocol or extention.

I also tried to simulate a Finder Keyboard shortcut for "Connect to Server...", but that didn't work either:

app("System Events").processes["Finder"].menu_bars[1].menu_bar_items["Go"].menus["Go"].menu_items["Connect to Server..."].click

Any ideas?

1

There are 1 best solutions below

0
On

Your second solution should work just fine, but replace the "Connect to Server..." with "Connect to Server…". That's the ellipsis character (option-;), not three periods in a row.

require 'appscript'

include Appscript

app('Finder').activate

# This is a slightly terser way of doing it :)
# app('System Events').processes['Finder'].menu_bars[1].menus['Go'].menu_items['Connect to Server…'].click

app("System Events").processes["Finder"].menu_bars[1].menu_bar_items["Go"].menus["Go"].menu_items["Connect to Server…"].click