Go Back   The macosxhints Forums > OS X Help Requests > System



Reply
 
Thread Tools Rate Thread Display Modes
Old 09-30-2005, 01:29 PM   #1
xSmurf
Prospect
 
Join Date: Dec 2002
Location: Montréal
Posts: 44
Question UI Script to switch Audio Output

Regarding this hint An AppleScript to change sound output device. I have create my own script similar to this one to switch the audio output to the iMic (which is the output for my bedroom stereo). The script works great... but only when I'm there. I use iCal to trigger the script as a wakeup alarm. The problem is it does not work the next morning when triggered automatically! AppleScript reports an NSReceiver error #4... I really don't understand why, any ideas?

Here's the code:
PHP Code:
on SetAudioOutput(theOutput)
    
tell application "System Preferences" to activate
    tell application 
"System Events"
        
tell process "System Preferences"
            
delay 2
            click menu item 
"Sound" of menu "View" of menu bar 1
            delay 4
            click radio button 
"Output" of tab group 1 of window "Sound"
            
delay 2
            set theRows to every row of table 1 of scroll area 1 of ¬
                tab group 1 of window 
"Sound"
            
delay 2
            set theOutputs to 
{} as list
            
repeat with aRow in theRows
                
if (value of text field 1 of aRow as text¬
                    is equal to theOutput then
                    set selected of aRow to true
                    
exit repeat
                end 
if
            
end repeat
        end tell
    end tell
    tell application 
"System Preferences" to quit
end SetAudioOutput

on iTunesRandomPlay
(newPlaylist)
    
tell application "iTunes"
        
set my_playlist to playlist newPlaylist
        activate
        next track
        repeat 2 times 
-- what the heckwhy not
            set shuffle of my_playlist to true
            set shuffle of my_playlist to false
        end repeat
        set shuffle of my_playlist to true
        play my_playlist
    end tell
end iTunesRandomPlay

SetAudioOutput
("iMic USB audio system")
delay 2
iTunesRandomPlay
("Morning"
__________________
Free iPods!
xSmurf is offline   Reply With Quote
Old 09-30-2005, 02:02 PM   #2
guardian34
All Star
 
Join Date: Jul 2004
Posts: 713
Quote:
Code:
 tell process "System Preferences" 
	delay 2 
	click menu item "Sound" of menu "View" of menu bar 1 
	delay 4 
	click radio button "Output" of tab group 1 of window "Sound"

FWIW, you should be able to simplify* that:
Code:
tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.sound"
	reveal (first anchor of current pane whose name is "output")
end tell
*See this thread at the MacScripter BBS.
guardian34 is offline   Reply With Quote
Old 10-01-2005, 04:27 PM   #3
xSmurf
Prospect
 
Join Date: Dec 2002
Location: Montréal
Posts: 44
Thanks for the tip. I have tried it and it seams to work. I've set up a test alarm for tomorrow morning, we'll see if it solves the problem
__________________
Free iPods!
xSmurf is offline   Reply With Quote
Old 10-03-2005, 05:19 AM   #4
xSmurf
Prospect
 
Join Date: Dec 2002
Location: Montréal
Posts: 44
Hmmmm it doesn't seam to have worked... Although it might have been me that screwed up. I'll test again next Thursday (can't right now).
__________________
Free iPods!
xSmurf is offline   Reply With Quote
Old 10-26-2005, 09:14 AM   #5
ScottRussell2
Triple-A Player
 
Join Date: Nov 2004
Location: Notre Dame, IN
Posts: 82
AppleScript to toggle audio

Hi there,

Here's a script a colleague wrote to toggle audio between devices. Perhaps this will help?

<his e-mail to me allowing me to post his code>
I dont have an account at the forums and probably wouldnt post much in the future. if you want to post this code, feel free to do so.

Code:
--This script toggles between two audio outputs in the "Sound" pane in "System Preferences.
--USES GUI SCRIPTING - "ENABLE ASSISTIVE DEVICES" OPTION MUST BE CHECKED IN "UNIVERSAL ACCESS" PREFERENCE PANE

tell application "System Preferences"
    activate
    set current pane to pane "com.apple.preference.sound"
end tell

tell application "System Events"
    tell application process "System Preferences"
        tell tab group 1 of window "Sound"
            click radio button "Output"
            if (selected of row 3 of table 1 of scroll area 1) then
                set selected of row 1 of table 1 of scroll area 1 to true
                set deviceselected to "Headphones"
            else
                set selected of row 3 of table 1 of scroll area 1 to true
                set deviceselected to "Speakers"
            end if
        end tell
    end tell
end tell

tell application "System Preferences" to quit

tell me to activate
display dialog "Audio output set to " & deviceselected buttons {"Cool"} default button 1
- - - - - - - -
David Klawiter
Center for Creative Computing
</his e-mail to me allowing me to post his code>
__________________
Best wishes,
Scott

http://www.nd.edu/~srussel2/
ScottRussell2 is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 07:52 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Site design © Mac Publishing LLC; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of Mac Publishing LLC.