Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Output Audio Device




On 1 Nov 2006, at 17:48, Adam Bell wrote:

When headphones, external speakers, or neither of the above (internal speaker) are connected, the Sound pane of System Preferences indicates the change. To be able to detect the configuration from an AppleScript, however, the only means I've been able to find is this one:
-----
activate application "System Preferences"
tell application "System Events" to tell process "System Preferences"
click button "Sound" of scroll area 1 of window "System Preferences"
delay 1
set S to value of text field 1 of row 1 of table 1 of scroll area 1 of tab group 1 of window "Sound"
end tell
-----
where the value of 'S' will be 'Internal Speakers', 'Line Output', or 'Headphones', depending on the hardware setup.


That's a rather brute force approach (which only works, BTW, if System Preferences is not running when it's invoked).

[snip]

You also need to make sure the relevant tab is selected, Adam. When I ran the above script, for example, I got the result "Basso" - because the last sound tab selected here was "Sound Effects".

1. Is there a cleaner way to open the sound pane directly?

In a word, yes. This should work regardless of System Preferences' current status - and with no explicit delay required:


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

tell application "System Preferences"
	reveal anchor "output" of pane id ¬
		"com.apple.preference.sound"
end tell
tell application "System Events"
	set S to value of text field 1 of row 1 of table 1 of ¬
		scroll area 1 of tab group 1 of window "Sound" of ¬
		application process "System Preferences"
end tell

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

---
kai


_______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/applescript-users/email@hidden Archives: http://lists.apple.com/mailman//archives/applescript-users

This email sent to email@hidden
References: 
 >Output Audio Device (From: Adam Bell <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.