Skip to main content

MacScript function

Table of contents
  1. Syntax
  2. Remarks

Executes an AppleScript script and returns a value returned by the script, if any.



The script argument is a String expression. The String expression either can be a series of AppleScript commands or can specify the name of an AppleScript script or a script file.


Multiline scripts can be created by embedding carriage-return characters (Chr(13)).

ThePath$ = Macscript("ChooseFile")

The MacScript command, used to support inline Apple Scripts in Office for Mac 2011, is being deprecated. Due to restrictions of the sandbox, the MacScript command can no longer invoke other applications such as the Finder. Therefore we discourage the use of this command.

For cases which require changing your existing code so it doesn’t use MacScript, you can use the AppleScriptTask command (see below).

The new AppleScriptTask command executes an AppleScript script. This similar to the MacScript command except that it runs an AppleScript file located outside the sandboxed app. Call AppleScriptTask as follows:

Dim myScriptResult as String
myScriptResult = AppleScriptTask ("MyAppleScriptFile.applescript", "myapplescripthandler", "my parameter string") 


  • The “MyAppleScript.applescript” file must be in ~/Library/Application Scripts/[bundle id]/, the extension applescript is not mandatory, .scpt may also be used
  • “myapplescripthandler” is the name of a script handler in the MyAppleScript.applescript file
  • “my parameter string” is the single input parameter to the “myapplescripthandler” script handler.
  • The corresponding AppleScript for Excel would be in a file named "MyAppleScriptFile.applescript" that is in ~/Library/Application Scripts/

Note: The [bundle id]s for Mac Word, Excel and PowerPoint are:


An example of a handler is as follows:

on myapplescripthandler(paramString)

    #do something with paramString
    return "You told me " & paramString

end myapplescripthandler

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>