Applescript/Shell Script reference to the app itself

Hi guys,

i have made an applescript with the following source code:

"

setsound_outputtobutton returnedof (display dialog "Select Output Source" buttons {"Computer", "TV"} default button "TV")

if sound_output is "Computer" then do shell script ("cd /Applications/SwitchAudioSource-v1; ./SwitchAudioSource -s 'Built-in Output'")

if sound_output is "TV" then do shell script ("cd /Applications/SwitchAudioSource-v1; ./SwitchAudioSource -s 'HDMI'")

"

I am wondering if there is a way to refer to the abovementioned executable ./SwitchAudioSource (currently located in /Applications) in my compiled applescript somewhere? That is:

Show Package Contents > Contents > Resources > and dump the executabe ./SwitchAudioSource here, and then modify my script to somehow refer to within itself so that my applescript will work regardless of where i place it. Desktop, /Users, even pictures,

i hope this makes sense, thankyou for all your help in advance, cheers mate 🙂

MacBook Pro, iOS 5.1

Posted on Mar 12, 2013 5:05 PM

Reply
6 replies

Mar 12, 2013 9:49 PM in response to Frank Caggiano

Hey man thanks for the quick reply,


i have changed script to:


set rf to POSIX path of (path to resource "SwitchAudioSource" in bundle path to me)

set sound_output to button returned of (display dialog "Select Output Source" buttons {"Computer", "TV"} default button "TV")

if sound_output is "Computer" then do shell script ("cd rf; ./SwitchAudioSource -s 'Built-in Output'")

if sound_output is "TV" then do shell script ("cd rf; ./SwitchAudioSource -s 'HDMI'")


i'm unsure how to reference this in my shell script??? sorry to muck you around, much appreciated for the tip in the right direction, cheers mate

Mar 13, 2013 7:29 AM in response to Benjamyn

OK didn;t realize you were putting the whole SwitchAudioSource folder in there.


try this then


set rf to POSIX path of (path to resource "SwitchAudioSource" in bundle path to me)


set sound_output to button returned of (display dialog "SelectOutputSource" buttons{"Computer", "TV"} default button "TV")



if sound_output is "Computer" then

do shell script rf & "SwitchAudioSource -s 'Built-in Output'"

else if sound_output is "TV" then

do shell script rf & "SwitchAudioSource -s 'HDMI'"

end if


rf will contain the full path to the folder SwitchAudioResource in the application bundle then we append the program in that folder to the path and run it.


I just cleaned up the if then statements.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript/Shell Script reference to the app itself

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