4.151
January 26, 2012
•
Home
www.reaper.fm
•
About
what it is
•
Purchase
cost: not so much
•
Resources
customize, modify, extend
•
Forum
discuss, share, learn
back to main reference page


ReaScript
  • Introduction
  • Requirements
  • ReaScript Documentation and Reference
  • Running ReaScripts
  • Calling REAPER Actions
  • ReaScript API
  • Advanced



top  Introduction

ReaScript is a feature that allows you to run Python scripts within REAPER. From within the script, you can call any REAPER action, and also call back into most of the REAPER API functions (the same API used by compiled REAPER plug-ins and extensions). ReaScript can be used to create anything from advanced macros to full-featured REAPER extensions.

Note: REAPER on Windows formerly supported Perl scripts as well, but Perl support was removed in REAPER version 4.14. ReaScript Perl will be reinstated when/if the Perl ctypes project is complete.


top  Requirements

To use ReaScript, you must have Python installed on your computer. ReaScript should work with any version of Python between 2.7 and the current 3.x release.

OS X normally comes with Python already installed. If you don't already have Python, it is available as a free download for Windows or Mac from multiple sources. For 32-bit REAPER, you need 32-bit Python (regardless of the operating system). For 64-bit REAPER, you need 64-bit Python.

A list of Python distributions is here.

Once Python is installed, REAPER should automatically detect it, and ReaScript will work. If REAPER does not detect Python, you can enter the Python install directory in REAPER preferences, under Plug-Ins/ReaScript.


top  ReaScript Documentation and Reference

From within REAPER, under the Help menu, choose "HTML lists/ReaScript documentation". This will open a web page with some basic documentation, and a complete list of all REAPER API functions that can be called from ReaScript.

There is extensive online documentation for Python 2 and Python 3.


top  Running ReaScripts

You will need to either write a script, or copy a script from another user. Scripts can be placed anywhere on your disk, but it's convenient to keep them all in the REAPER/Scripts application data directory.

To write a new script, show the Actions list (bound to the ? key by default), and click ReaScript: New/Load. You will be prompted for the location to save your new script. The default location is the recommended REAPER/Scripts application data directory. Name your script something like test.py, then click ReaScript: Edit. A text editor will open.

The simplest possible ReaScript is:

RPR_APITest()

Save the ReaScript, and then click Run. You should see a window that says "Test OK". Common reasons for the script failing are:
  • Python not installed
  • REAPER cannot find the installed Python
  • Syntax error (typo, missing newline, incorrect indentation in Python)
You can treat a ReaScript just like any custom action: bind it to a key shortcut, MIDI controller, or toolbar button. ReaScripts can also be run a la carte, via the actions "ReaScript: run..." and "ReaScript: run last script".


top  Calling REAPER Actions

You can call any REAPER action from ReaScript by using the API function

RPR_Main_OnCommand(actionnumber, 0)

Find the action number for a given action by opening the Actions list, and scrolling the window right to reveal an extra column. For example, from ReaScript you would call the REAPER action "Item: Split item under mouse cursor" like this:

RPR_Main_OnCommand(40746, 0)

If you use ReaScript as an advanced macro language, this is the only API function you need to know.


top  ReaScript API

ReaScripts also have access to most of the REAPER Extension API functions. For a list of all API functions available to ReaScripts, see the built-in ReaScript documentation. That help page will explain the basics of how to call API functions, which may require idiosyncratic syntax, because API functions can return information in the parameter list as well as the function return value. For convenience, there are also basic API functions for getting information from, and showing information to, the user.


top  Advanced

You can set a custom editor for Python scripts in REAPER's Preferences/External Editors, by assigning an application to the ".py" extension.

ReaScripts can keep persistent state by using the API functions RPR_SetExtState() and RPR_GetExtState(). This allows ReaScripts to set key/value pairs (similar to a Python dictionary) that will persist between ReaScripts, and optionally persist between REAPER instances as well. For example, a module called "utility" might want to remember that some flag is set:

RPR_SetExtState("utility", "someflag", "2", True)
val=RPR_GetExtState("utility", "someflag") # even if called after REAPER is closed and reopened, val will be equal to "2"


You can create and save modules of useful functions that you can import into other ReaScripts. For example, if you create a file called reascript_utility.py that contains the function helpful_function(), you can import that file into any ReaScript with the line

import reascript_utility

and call the function by using

reascript_utility.helpful_function()

Note that reascript_utility.py must itself import reaper_python, with the line

from reaper_python import *

(Although it is not required, it is good practice to start all ReaScripts with that line.)



For more help on ReaScript, to report bugs, to request additional API functions, to share ReaScripts, or just to discuss the possibilities, please use the
REAPER ReaScript Forum.
Home
Company
Reviews
About
Uses
Audio
MIDI
Technical
Download
User Guide
Old Versions
ReaPlugs
Purchase
Distribution
Developer
JS Programming
• ReaScript
Extensions SDK
Extensions to VST SDK
Resources
Forum
Stash
Wiki
© 2005-2012 Cockos Incorporated