Share via

run applescript file from word

Anonymous
2012-04-04T00:46:59+00:00

I have a applescript file 'command.scpt'. Can I run this from Word? I know I can create a string with the commands and use MacScript (string), but can I just run the file?

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-04-05T05:23:10+00:00

Have you been able to run anything at all through MacScript? Have you tested it with a simpler script like Peter suggested?

Try adding return "SOME STRING" at the end of the script. Perhaps Word is expecting something back and not getting it causes an error. I'm thinking something similar to the error that happens if you press Cancel with Print  MacScript ("display dialog ""Click OK""") in the Immediate box.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

Anonymous
2012-04-05T08:11:24+00:00

No further suggestions yet, but just reporting back my own findings here.

I tried your script (with similar command lengths) using the /usr/bin version of sqlite3, a simple test database with a single table and a couple of rows, and a sql script consisting of "SELECT * FROM mytable;"

That ran OK from Applescript, and via Word VBA Macscript, and populated the temp.csv file.

I downloaded sqlite3, unzipped into the r4w/Temp folder, renamed, modified the script and tried again.

That also ran OK from Word VBA and populated the temp file.

I also tried running from Excel VBA and that was OK too (unlike the other problem I mentioned).

So it does not seem that there is anything about sqlite3 itself, or the length of your command (unless it's down to a length difference of a couple of characters or so) that is causing the problem. If you can run a simple one-liner .scpt from Word VBA successfully then it isn't an obvious problem with Word invoking applescript.

The only thing I can think of right now is that...

AFAICS, when Word runs the script, the script should in effect behave as if it is wrapped as follows:

tell application "Microsoft Word"

end tell

you should be able to verify that scripts are "telling" Microsoft Word by running a one-liner like


set appname to the name of the current application

instead of your script.

If the current application actually turns out to be something else, that would be need to be looked at (but wouldn't necessarily solve the problem). I'm not sure that in a more complex scenario, Word would necessarily be the current application, but I would expect it to be when you execute macscript from the VBE immediate window.

Was this answer helpful?

0 comments No comments

16 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-04-04T03:44:55+00:00

    In Mac2011 vba, if I enter:

    dim filewithscriptinit as string

    filewithscriptinit = pathtoAppleScriptFile

    retval = MacScript(filewithscriptinit)

    This code will yield an error: Type Mismatch.

    It seems to want the string of the actual script, not the .scpt file.

    The Word VBA help file (Word 2010) shows that you can use a script file, yet doesn't say how.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-04-04T02:48:18+00:00
    • Open AppleScript Editor
    • Select Preferences > General
    • Enable Show Script menu in menu bar (this will add a new icon next to the clock)
    • Navigate to /Users/YOURNAME/Library/Scripts (if you are on Lion, use the Finder's Go > Go to Folder menu while pressing the Option key)
    • There should be an Application folder there. If not, create it.
    • Inside, place another folder called Word and store your script there

    Now your script should be accessible from the new icon in the menu bar.

    Was this answer helpful?

    0 comments No comments
  3. Jim G 134K Reputation points MVP Volunteer Moderator
    2012-04-04T02:33:15+00:00

    Hi Paul,

    I'm a bit confused because you seem to have already answered your question. The way you run an Applescript from Word would be to use the Macscript method in VBA. Alternatively, you can put scripts into the Script menu and choose them from the menu.

    Was this answer helpful?

    0 comments No comments