Mac Office 2011 VBA - server call script

I am moving a large VBA project from Windows to the new Mac Word 2011. This is really very good ... almost all of the code works.

My code should call scripts on my server. On Windows, I call the system function InternetOpenUrl to call the script and InternetReadFile to read the results returned by the script. For example, I call the script as follows:

  "http://www.mysite.com/cgi-bin/myscript.pl?param1=Hello&param2=World

and it returns a string like success

What is the best way to make an equivalent on a Mac? Uses Applescript (via vba MacScript function) answer? I do this to display a file selection dialog, but I can’t find what applescript will look like to invoke the script online image. Or is there a better / faster way to do this?

Thanks in advance, Gary

+3
source share
2 answers

You can try using the URL access scripting library, which is the interface for curl, or go to the script through the browser and read the text there.

0
source

I recently figured this out in order to call the server to convert the LaTeX user string into an equation image. The call is made through VBA using the command MacScript:

command = "do shell script """ & pyPath & "python " & getURLpath & "getURL.py --formula '" _
          & Latex_Str & "' --fontsize " & Font_Size & " " & WebAdd & """"
result = MacScript(command)

, do shell script /usr/bin/python {path to script}/getURL.py --formula '{LaTeX formula string}' --fontsize {int} {myurl} . Python script argparse , , urllib urllib2 . MacScript stdout Python script result.

urllib2 Python script.

EDIT: , . Python script .

# Import the required libraries
from urllib import urlencode
from urllib2 import Request, urlopen, URLError, ProxyHandler, build_opener, install_opener
import argparse

# Set up our argument parser
parser = argparse.ArgumentParser(description='Sends LaTeX string to web server and returns meta data used by LaTeX in Word project')
parser.add_argument('webAddr', type=str, help='Web address of LaTeX in Word server')
parser.add_argument('--formula', metavar='FRML', type=str, help='A LaTeX formula string')
parser.add_argument('--fontsize', metavar='SIZE', type=int, default=10, help='Integer representing font size (can be 10, 11, or 12. Default 10)')
parser.add_argument('--proxServ', metavar='SERV', type=str, help='Web address of proxy server, i.e. http://proxy.server.com:80')
parser.add_argument('--proxType', metavar='TYPE', type=str, default='http', help='Type of proxy server, i.e. http')

# Get the arguments from the parser
args = parser.parse_args()

# Define formula string if input
if args.formula:
    values = {'formula': str(args.fontsize) + '.' + args.formula}   # generate formula from args
else:
    values = {}

# Define proxy settings if proxy server is input.
if args.proxServ:       # set up the proxy server support
    proxySupport = ProxyHandler({args.proxType: args.proxServ})
    opener = build_opener(proxySupport)
    install_opener(opener)

# Set up the data object
data = urlencode(values)
data = data.encode('utf-8')

# Send request to the server and receive response, with error handling!
try:
    req = Request(args.webAddr, data)

    # Read the response and print to a file
    response = urlopen(req)
    print response.read()

except URLError, e:
    if hasattr(e, 'reason'):    # URL error case
        # a tuple containing error code and text error message
        print 'Error: Failed to reach a server.'
        print 'Reason: ', e.reason
    elif hasattr(e, 'code'):    # HTTP error case
        # HTTP error code, see section 10 of RFC 2616 for details
        print 'Error: The server could not fulfill the request.'
        print 'Error code: ', e.code
0

Source: https://habr.com/ru/post/1773188/


All Articles