« Back to jordanbalagot.com
Keep your MIDI keyboard active with Mainstage and Applescript: Keep Mainstage Running.app

Posted on Thursday 8 April 2010

I know I’m not the only one with this problem: You have this giant MIDI keyboard that doesn’t produce sound on its own, and most of the time, playing it doesn’t do anything. You have to launch logic, or mainstage, or ableton, or digital performer, open a new project, setup a new patch, and then start playing. In music classes, this can be a distraction, and compositionally, it can get in the way between you and your creativity.

I’d keep MainStage open all the time, but there are times when I don’t want a secondary keyboard sound when I’m using Finale or Logic. Ideally, anytime I’m not using Finale or Logic, I’d like MainStage to be running.

I’ve written a simple OS X application in applescript that checks every 30 seconds to see if Logic or Finale are running, and if they’re not, launches MainStage in the background. It takes up very little CPU and can run continuously. Here is the code:

[code lang=”applescript”]
tell application “System Events”
if not (exists process “Logic Pro”) then
if not (exists process “Finale 2010”) then
if not (exists process “MainStage”) then
set front_app to (path to frontmost application as Unicode text)
tell application “MainStage” to activate
set visible of process “MainStage” to false
tell application front_app to activate
end if
end if
end if
end tell
delay 30
end repeat

If you’re on mac you can open that code in the script editor by clicking
here. (Thanks to Mac Developer tips for that trick.)

I have created two downloadable versions, a regular version and a silent version that does not appear in the dock.

Note that the silent version is VERY silent, i.e. you do not see it in the dock, nor in the force quit window. A quick way to kill it is to run “killall applet” in the terminal, though this will kill other applescripts you have running as well.

A more precise way to kill it is to run this command in the terminal:
ps -ax | grep -i “keep mainstage”

Get the first process number listed (usually 5 digits) and then run:
kill XXXXX (where XXXXX is the process number)

You can point to either of these apps in your System Preferences > Accounts > Login Items to have them run automatically when you start your computer.

You should set MainStage’s startup action in preferences to “Open Most Recent Concert”. I have a simple concert with just a piano that I keep open.

Included in the download above are instructions on how to make the silent app run in the background again if you modify it.

Known Bugs with 1.0:
For some reason you have to force-quit the non-silent version, quitting alone does not work.

MainStage has an annoying behavior of grabbing focus once a concert has loaded. The script hides MainStage after it does this, but you will still see it briefly pop up when it launches.

The script will not launch Mainstage if you have Logic or Finale running but with no documents open.

The script may launch Mainstage at annoying times (such as shutdowns or software updates). I’d recommend just shutting down with mainstage running, and clicking “don’t save” if it asks.

1 Comment for 'Keep your MIDI keyboard active with Mainstage and Applescript: Keep Mainstage Running.app'

    October 6, 2010 | 9:02 pm

    […] written another app similar to my keep mainstage running app — Quicksilver Or Steam. It is more responsive than my last app, and I’ve written a […]

Leave a comment



Information for comment users
Line and paragraph breaks are implemented automatically. Your e-mail address is never displayed. Please consider what you're posting.

Use the buttons below to customise your comment.

RSS feed for comments on this post | TrackBack URI