[Pythonmac-SIG] ASTranslate and appscript question

Ned Deily nad at acm.org
Fri Mar 28 23:24:18 CET 2008


In article <87E0DE88-4181-47A9-A7EA-D473B5BBCB90 at post.harvard.edu>,
 Robert Pyle <rpyle at post.harvard.edu> wrote:
> From a python program, I'm trying to set the input and output gains  
> of a USB audio interface (M-Audio Transit).  Using ASTranslate, I've  
> been able to write appscript code to manipulate the "Sound" preference  
> panel of "System Preferences" to find and make note of the current  
> sound input and output devices, select the Transit as the default  
> device, and then restore the prior default device (which may or may  
> not be the Transit).
> 
> What I can't do so far is figure out how to set the gain while the  
> Transit is selected.  When the Transit is the selected default device,  
> this AppleScript sets the gains as I want:
> 
> ---------
> tell application "Finder"
> 	set volume output volume 100
> 	set volume input volume 35
> end tell
> ---------

"set volume" is not a Finder command, rather it is provided by the 
StandardAdditions scripting addition (an "osax").  You can see this in 
Script Editor.app by looking at their dictionaries (and the above 
applescript commands would work outside of a tell block, too). The osax 
module of py-appscript provides a way to call scripting additions.  So, 
something like this should work:

   import osax
   sa = osax.ScriptingAddition()  # default is StandardAdditions
   sa.set_volume(output_volume=100, input_volume=35)

If you have ASDictionary.app installed, you can look at the 
appscript/osax syntax of StandardAdditions easily by its menu item:
Dictionary -> Choose Installed Scripting Additions...

-- 
 Ned Deily,
 nad at acm.org



More information about the Pythonmac-SIG mailing list