1

So I'm trying to have a button in my Excel spreadsheet launch a Python script. Apparently this is only possible on Windows, so on the Mac version people have a workaround where they use Excel to launch an AppleScript which then launches a Python script.

In Automator I've tried selecting Application, and when that didn't work I selected Quick Action, and both times I inserted a 'Run Shell Script' module.

Within that I set the Shell to 'usr/bin/python' and Pass input as 'As Arguments'. Then in the text field I put

do shell script "/Users/user_name/Desktop/integrationtest.py"

and I tried

do shell script "python /Users/user_name/Desktop/integrationtest.py"

When I click Run in the top right of Automator it says

The action “Run Shell Script” encountered an error: “  File "<string>", line 1
    do shell script "/Users/user_name/Desktop/integrationtest.py"
           ^
SyntaxError: invalid syntax”

  File "<string>", line 1
    do shell script "/Users/user_name/Desktop/integrationtest.py"
           ^
SyntaxError: invalid syntax

Not too sure what I'm doing wrong - any ideas? Thanks for any help

1
  • I'll point out that Automator has a Run Shell Script action, which might give better results than trying to run your shell script from do shell script in AppleScript. I'm not really up on Excel buttons, though, so I'll have to look into that later. Commented Aug 19, 2019 at 17:15

2 Answers 2

1

You are mixing up AppleScript and Shell Script syntax.

  • The Run Shell Script action syntax is

    python /Users/user_name/Desktop/integrationtest.py
    
  • The Run AppleScript action syntax is

    on run {input, parameters}
        do shell script "python /Users/user_name/Desktop/integrationtest.py"
        return input
    end run
    
Sign up to request clarification or add additional context in comments.

Comments

0

I suggest you to go step by step : first open Terminal application and test that your python script runs fine :

python /Users/user_name/Desktop/integrationtest.py

if OK, then open Applescript Editor and create a script with single line : (in Applescript, some environment settings may be different from usual bash Terminal)

do shell script "python /Users/user_name/Desktop/integrationtest.py"

If again this Applescript test works as expected, then call this Applescript from Excel. The method to call depends of your Excel version: With Excel 2011, use Macscript function, and with Excel 2016 use ApplescriptTask.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.