Jump to content
arnaud.mar

A usefull Applescript code for audiophiles (?)

Rate this topic

Recommended Posts

Folks,

Here is a code that I wrote in order to :

 

1- set up the Digital Output audio of your Mac

2- Launch iTunes and select an equalizer

3- Advertize the user by a Crowl message

 

Of course, it can be easily adapted to select the Analog Out, Headphone, etc...

 

I hope it will be useful to some of you!

Arnaud

PS : it works under OS 10.6.7

 

 

-------------------------------------------------

 

tell application "System Preferences"

activate

set the current pane to pane id "com.apple.preference.sound"

get the name of every anchor of pane id "com.apple.preference.sound"

reveal anchor "output" of pane id "com.apple.preference.sound"

end tell

 

tell application "System Preferences" to activate

tell application "System Events"

get properties

tell process "System Preferences"

set theRows to every row of table 1 of scroll area 1 of ¬

tab group 1 of window "sound"

set theOutputs to {} as list

repeat with aRow in theRows

if (value of text field 1 of aRow as text) ¬

is equal to "Digital Out" then

set selected of aRow to true

exit repeat

end if

end repeat

end tell

end tell

tell application "System Preferences" to quit

 

tell application "iTunes"

set the current EQ preset to EQ preset "Pop"

set theEqPresetName to name of the current EQ preset

end tell

 

tell application "GrowlHelperApp"

 

set the allNotificationsList to ¬

{"EQ Preset Changed"}

 

set the enabledNotificationsList to ¬

{item 1 of allNotificationsList}

 

register as application ¬

"Toggle Equalizer Preset" all notifications allNotificationsList ¬

default notifications enabledNotificationsList ¬

icon of application "Script Editor"

 

notify with name ¬

"EQ Preset Changed" title ¬

"iTune EQ Preset Changed to :" description ¬

theEqPresetName application name "Toggle Equalizer Preset"

end tell

Share this post


Link to post
Share on other sites

If you play music with different sample rates, to avoid undesired sample rate conversion you might want to further refine your AppleScript to set the sample rate of the output device to the sample rate of the tracks you intend to play in iTunes. The issue is explained in this old thread:

http://www.computeraudiophile.com/threads/2339-AppleScript-to-automatically-change-Sample-Rate-in-Audio-MIDI-Setup

 

Here's a script I wrote to set the default audio device to the DAC specified in the variable "DACname" and to set its sample rate to 44.1, assuming that is the lowest sample rate supported by the DAC. To change the sample rate you must use the Audio MIDI Setup application rather than Sound prefs.

 

I actually don't use this script anymore because Audirvana Plus, Pure Music, and Bit Perfect handle this automatically. I believe Bit Perfect only costs $5 in the Apple App Store.

 

-- BEGIN APPLESCRIPT --

 

set DACname to "LIO-8 [223]"

--set DACname to "Built-in Output"

 

set newDefaultDeviceName to DACname --"Built-in Output"

set newAlertDeviceName to "Built-in Output"

 

set menuDefaultOut to "Use this device for sound output"

set menuAlert to "Play alerts and sound effects through this device"

 

 

--if application "iTunes" is running then tell application "iTunes" to stop

 

activate application "Audio MIDI Setup"

tell application "System Events"

tell process "Audio MIDI Setup"

try

click menu item "Show Audio Window" of menu 1 of menu bar item "Window" of menu bar 1

end try

 

--Set Nrows to number of audio devices:

set rowList to value of attribute "AXVisibleRows" of outline 1 of scroll area 1 of window "Audio Devices"

end tell

end tell

set Nrows to count of rowList

 

 

--Select desired audio device (row N):

set Failure to true

tell application "System Events"

tell process "Audio MIDI Setup"

repeat with N from Nrows to 1 by -1

set deviceName to value of text field 1 of row N of outline 1 of scroll area 1 of window "Audio Devices"

if deviceName = DACname then

select row N of outline 1 of scroll area 1 of window "Audio Devices"

set Failure to false

exit repeat

end if

end repeat

end tell

end tell

 

if Failure then

display dialog "Missing device: " & DACname

return --Quit the script.

end if

 

 

--Set sample rate to lowest value (44.1):

tell application "System Events"

tell process "Audio MIDI Setup"

click button 1 of combo box 1 of group 1 of tab group 1 of group 1 of window "Audio Devices"

repeat 10 times

key code 126 -- up arrow Key

end repeat

key code 36 --return key

 

end tell

end tell

 

 

SetAudioDevice(newAlertDeviceName, menuAlert)

SetAudioDevice(newDefaultDeviceName, menuDefaultOut)

 

-- END MAIN --

 

 

on SetAudioDevice(myDeviceName, myType)

activate application "Audio MIDI Setup"

tell application "System Events"

tell process "Audio MIDI Setup"

 

-- Open Audio Devices window if it is closed:

try

click menu item "Show Audio Window" of menu "Window" of menu bar item "Window" of menu bar 1

end try

 

-- List of Audio Devices in left column:

tell outline 1 of scroll area 1 of window "Audio Devices"

set N to 0

 

-- Set N to index of desired device:

repeat with k from 1 to (count of rows)

--set deviceName to value of text field 1 of row k

--display dialog (k as text) & deviceName

if value of text field 1 of row k = myDeviceName then

set N to k

exit repeat

end if

end repeat

if N = 0 then

display dialog "Desired Audo Device not found."

quit

end if

 

--Select desired output device:

select row N

end tell

 

--Use this device for sound output:

tell window "Audio Devices"

click menu button 1

click menu item myType of menu 1 of menu button 1

--click menu item "Use this device for sound output" of menu 1 of menu button 1

end tell

 

end tell

end tell

end SetAudioDevice

 

-- END APPLESCRIPT --

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×