Need help on script

Discussion in 'Mac Basics and Help' started by flash1996, Oct 28, 2013.

  1. flash1996, Oct 28, 2013
    Last edited by a moderator: Oct 29, 2013

    flash1996 macrumors newbie

    Joined:
    Oct 27, 2013
    #1
    I have this script that only works once the system preferences is open and giving this error. "System Events got an error: Can’t get window \"sound\" of process \"System Preferences\"." number -1728 from window "sound" of process "System Preferences"

    here is the script
    Code:
    tell application "System Preferences" to activate
    tell application "System Events"
    get properties
    tell process "System Preferences"
    delay 3
    click menu item "Sound" of menu "View" of menu bar 1
    delay 2
    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
    copy (value of text field 1 of aRow as text) to the end of theOutputs
    end repeat
    tell application "Finder"
    activate
    set desiredOutput to display dialog ¬
    "Choose Sound Output: " buttons theOutputs default button "Headphones"
    end tell
    repeat with aRow in theRows
    if (value of text field 1 of aRow as text) is equal to ¬
    (button returned of desiredOutput as text) then
    set selected of aRow to true
    exit repeat
    end if
    end repeat
    end tell
    end tell
    tell application "System Preferences" to quit
    BTW I'm on the new mavericks
     
  2. kryten2, Oct 28, 2013
    Last edited: Oct 28, 2013

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Try this :

    Code:
    tell application "System Preferences"
    	launch
    	activate
    	tell application "System Events"
    		get properties
    		tell process "System Preferences"
    			delay 3
    			click menu item "Sound" of menu "View" of menu bar 1
    			delay 2
    			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
    				copy (value of text field 1 of aRow as text) to the end of theOutputs
    			end repeat
    			tell application "Finder"
    				activate
    				set desiredOutput to display dialog ¬
    					"Choose Sound Output: " buttons theOutputs default button "Headphones"
    			end tell
    			repeat with aRow in theRows
    				if (value of text field 1 of aRow as text) is equal to ¬
    					(button returned of desiredOutput as text) then
    					set selected of aRow to true
    					exit repeat
    				end if
    			end repeat
    		end tell
    	end tell
    end tell
    tell application "System Preferences" to quit
    Instead of :

    Code:
    click menu item "Sound" of menu "View" of menu bar 1
    you can do something like this :

    Code:
    tell application "System Preferences"
    	launch
    	activate
    	reveal anchor "Output" of pane id "com.apple.preference.sound"
    	tell application "System Events"
    		tell process "System Preferences"
    			set theRows to every row of table 1 of scroll area 1 of ¬
    				tab group 1 of window "Sound"
    			-- etc
    		end tell
    	end tell
    end tell
     

Share This Page