Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript syntax do shell scripts

Hi guys,

i am having endless issues with the syntax of the following applescript. Please help me and i'll make you my new god, cheers. The

applescript syntax is:





tell application "Finder"


display dialog ¬

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

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

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


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

if button returned of result = "Computer" then InternalSpeakers

if button returned of result = "Computer" then HDMI

end tell


at the moment i am getting the following error:

User uploaded file

User uploaded file


I have tried arranging and re-arranging the applescript to no avail, please help me 😟

MacBook Pro, iOS 5.1

Posted on Feb 27, 2013 6:19 PM

Reply
Question marked as Best reply

Posted on Feb 27, 2013 7:17 PM

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"


ifbutton returnedofresult = "Computer" then

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



else
ifbutton returnedofresult = "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.

2 replies
Question marked as Best reply

Feb 27, 2013 7:17 PM in response to Benjamyn

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"


ifbutton returnedofresult = "Computer" then

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



else
ifbutton returnedofresult = "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.

AppleScript syntax do shell scripts

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.