« February 2007 | Main | April 2007 »
March 16, 2007
Give Judy My Notice
Think was updated to 1.1 this week, and I wanted to take a few bytes to point out the developer note we posted in regards to some new stuff in the app.
Third-party developers who want to know what Think is doing should read the Think 1.1 developer note and observe the NSDistributedNotificationCenter goodness.
Personally, I think it'd be neat to see someone integrate it with Twitter to announce what I'm currently thinking about. But that's just me. :)
In addition to that, Think 1.1 changes include:
- The illumination panel can now be operated entirely by the keyboard. Yeah, it totally makes a difference. Tab and shift-tab to cycle through the list; enter, return, or space to illuminate a highlighted app; and escape to dismiss the panel instead.
- Fixed instances where the illumination panel would not update its list of applications when new apps were launched or existing apps were quit.
- Other minor bug and performance fixes.
Posted by mikey at 11:16 AM | Comments (0)
March 15, 2007
New Everything: Using AppleScript with Sound Studio 3
Today's monkeybloggery comes from a post I made recently on our forums.
One of our (awesome) users wanted to know if Sound Studio 3 had a command to create a new document from the current selection. While Sound Studio can't do it directly, I knew it could be done with a quick bit of AppleScripting, so I jumped in and posted a script I'd written previously to accomplish the task. (The real power of AppleScript is making smart applications do things they can't normally do, after all.)
I took a second look at my old script this morning, the one I posted, and realized it needed some improvements to bring it up to normal standards. I'd like to walk our readers through writing the script, to demonstrate a little bit of how to work with Sound Studio via AppleScript.
Slow Moves
Diving straight past the run and application tell lines:
- on run
- tell application "Sound Studio"
- if ((count of windows) > 0) then
- set sourceDocument to window 1
In the first highlighted line, we want to make sure that Sound Studio actually has at least one document open before executing the rest of the script. By doing this, we eliminate "undefined" behaviour as well as avoid running the rest of the script, in the event there's nothing to do.
In the second line, we're going to create a reference to the frontmost window—the one we're going to be copying the selection from—so we can use it later without needing to know what order our windows are in before we use them. The idea is that a random keystroke, mouse click, or even another script could change the order of Sound Studio's windows, and we don't want to have to worry about that causing problems.
Doing this also has the benefit of making your script more readable, and that's always a plus.
- on run
- tell application "Sound Studio"
- if ((count of windows) > 0) then
- set sourceDocument to window 1
- set startTime to start time of selection of sourceDocument
- set stopTime to stop time of selection of sourceDocument
Another way to make the script smarter is to make sure that there is audio selected in the current document. We'll start by recording the values of the beginning and end of the current selection. If there is no selection, we'll get back the location of the blinking cursor for both values.
- on run
- tell application "Sound Studio"
- if ((count of windows) > 0) then
- set sourceDocument to window 1
- set startTime to start time of selection of sourceDocument
- set stopTime to stop time of selection of sourceDocument
- if (startTime ≠ stopTime) then
- [...]
- end if
If they don't match, our selection is greater than 0 seconds. (That is, there actually is a selection with which to create a new document!) Now we're ready to do some work.
- on run
- tell application "Sound Studio"
- if ((count of windows) > 0) then
- set sourceDocument to window 1
- set startTime to start time of selection of sourceDocument
- set stopTime to stop time of selection of sourceDocument
- if (startTime ≠ stopTime) then
- -- The script uses the clipboard, so make sure we record the current contents of the clipboard.
- set previousClipboardContents to the clipboard
- copy selection of sourceDocument
- [...]
- end if
To bounce audio back and forth between Sound Studio documents using AppleScript, you need to use the clipboard. However, this presents us with a problem, because once you copy audio data to the clipboard, whatever was there before will be lost forever. Now, realistically, a user should never have "volatile" (that is, non-replaceable) data on the clipboard, but it happens. Furthermore, since there's no indication of what's going on in the background, it's potentially confusing and frustrating for the user if suddenly what he thought was there is nowhere to be found.
To circumvent this problem, we need to record the current state of the clipboard before we start bouncing audio. When we're done, we'll put things back where we found them. You'll see this part later.
After we've recorded the state of the clipboard for future use, we're safe to copy the current selection of audio to the clipboard.
- on run
- tell application "Sound Studio"
- if ((count of windows) > 0) then
- set sourceDocument to window 1
- set startTime to start time of selection of sourceDocument
- set stopTime to stop time of selection of sourceDocument
- if (startTime ≠ stopTime) then
- -- The script uses the clipboard, so make sure we record the current contents of the clipboard.
- set previousClipboardContents to the clipboard
- copy selection of sourceDocument
- make new document
- set newDocument to window 1
- [...]
- end if
This part is pretty straightforward. Now that we've got our selection on the clipboard, we need to create a new document window and then make a reference to it, like we did with our sourceDocument reference.
Okay, now here's the fun part:
- on run
- tell application "Sound Studio"
- if ((count of windows) > 0) then
- set sourceDocument to window 1
- set startTime to start time of selection of sourceDocument
- set stopTime to stop time of selection of sourceDocument
- if (startTime ≠ stopTime) then
- -- The script uses the clipboard, so make sure we record the current contents of the clipboard.
- set previousClipboardContents to the clipboard
- copy selection of sourceDocument
- make new document
- set newDocument to window 1
- paste selection of newDocument existing 0 pasteboard 0 inside no
- [...]
- end if
There are four things going on in this line:
paste selection of newDocument: The actual paste selection command is a bit strangely worded, in that it doesn't mean "paste the current selection somewhere". Instead, this part's saying, "Paste into the current selection of newDocument."
existing 0: Sound Studio has the ability to mix intelligently what you're about to paste with what's already there. Measured in floating point decibels, the existing value determines what adjustment to make to the section you're about to paste into.
pasteboard 0: Measured in floating point decibels, the pasteboard value determined what adjustment to make to the audio being pasted into the current selection from the clipboard.
inside no: Passing no here tells Sound Studio that you don't want the length of the audio you're pasting to be limited by the length of the selection into which it's being pasted.
- on run
- tell application "Sound Studio"
- if ((count of windows) > 0) then
- set sourceDocument to window 1
- set startTime to start time of selection of sourceDocument
- set stopTime to stop time of selection of sourceDocument
- if (startTime ≠ stopTime) then
- -- The script uses the clipboard, so make sure we record the current contents of the clipboard.
- set previousClipboardContents to the clipboard
- copy selection of sourceDocument
- make new document
- set newDocument to window 1
- paste selection of newDocument existing 0 pasteboard 0 inside no
- -- Restore the user's clipboard to its previous state.
- set the clipboard to previousClipboardContents
- end if
- end if
- end tell
- end run
Now all we need to do is restore the contents of the clipboard we saved earlier. Close our statements, and we're done.
The Salmon Sounds Good, but What Else Is on the Menu?
Now we just need a convenient way to run the script. Luckily, Apple's solved this one for us. Here's info on how to enable and use the Script Menu in Mac OS X:
http://www.apple.com/applescript/scriptmenu/
A copy of the script can be downloaded here:
Posted by mikey at 01:47 PM | Comments (0)
The best Sound Studio update ever.
Perhaps you noticed the new, fantastic, state-of-the-art More Cowbell feature in the list of new features in Sound Studio 3.5.
Yes, it's a real feature.

Freeverse has toiled long and hard to integrate this envisioning of bovine-locating technology directly into Sound Studio.
Select part of your waveform, drop down your Filters menu, and fiddle with your Shift key.
Enjoy! If you haven't updated yet, check out the Sound Studio page by clicking here.
Posted by Justin at 11:50 AM | Comments (0)
