Pages

Thursday, February 28, 2013

Re: AppleScript syntax do shell scripts

You're over complicating the situation. This

 

set InternalSpeakers to (do shell script "cd ~/Downloads/SwitchAudioSource-v1; ./SwitchAudioSource -s 'Built-in Output'")

  --InternalSpeakers is now a variable which changes the sound output to Computer

 

sets InternalSpeakers to what the do shell script returns. It does not set InternalSpeakers to hold the do shell script command to run when you access the variable. There are ways to do this but its not needed here. Just do thsi as a simple if then else

 

display dialog ¬

                    "Select Output Source" buttons {"Computer", "TV"} default button "TV"

 

if button returned of result = "Computer" then

     do shell script "cd ~/Downloads/SwitchAudioSource-v1; ./SwitchAudioSource -s 'Built-in Output'"

 

 

else    if button returned of result = "TV" then


    do shell script "cd ~/Downloads/SwitchAudioSource-v1; ./SwitchAudioSource -s 'Soundflower (16ch)'"

 

 

end if

 

Something like this will work.  Also there is no reason for the code you show to do it in a tell block. The Finder isn;t needed for this.


View the original article here

0 comments:

Post a Comment