1

I'm trying to create a shortcut to start system preferences and open the sound settings in the "in" tab.

So far I have started system preferences and opend up the audio settings, maybe not in the most elegant way possible but for having started with applescript today I'm quite proud.

Anyways, currently this is my "code":

on run{input, parameters}

    activate application "System Preferences"
    delay 0.8
    tell application "System Events" to tell process "Systeminställningar"
        tell menu bar item 4 of menu bar 1
            click
            click menu item "Ljud" of menu 1
        end tell
    end tell

    return input
end run

Bare in mind that my system is in Swedish so the "Systeminställningar" means "System Preferences" and "Ljud" means "Audio" and "Ljud in" means "Audio in"

Thanks in advance.

Update: Actually just a few minutes after I wrote this I figured out a way to do (new code):

on run{input, parameters}

    activate application "System Preferences"
    delay 0.8
    tell application "System Events" to tell process "Systeminställningar"
        tell menu bar item 4 of menu bar 1
            click
            click menu item "Ljud" of menu 1
        end tell
        delay 1
        tell tab group 1 (*New code starts here*)
            click
            click radio button "Ljud in" of tab 1
        end tell
    end tell (*Ends here*)

    return input
end run

But I still would love some constructive criticism for how to do this better since I'm fairly certain that this is far from effective.

0

You can use the AppleScript command from the System Preferences application instead of the GUI scripting

tell application "System Preferences"
    -- open the audio pane and select the "Audio in" tab
    reveal anchor "input" of pane id "com.apple.preference.sound"
    activate
end tell

tell application "System Events" to tell process "Systeminställningar"
    -- do something in "Ljud in" tab
end tell

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .