Run bash script via button in interface builder?

Joined
Feb 18, 2011
Messages
4
Reaction score
0
Points
1
Hi,
I've searched for the answer to this for days and have hit a wall, hoping someone can help. With interface builder and Xcode, i've built an app that opens applescripts when buttons are pressed. This is working fine, but I need one of the buttons to run a #!/bin/bash script. I've worked around it by creating an applescript which just opens the bash script, but (with my limited knowledge) this required a specific path to the file, and i'd like to have interface builder just run the bash script on it's own when the button is pressed.

Thanks for any responses, any help is greatly appreciated.
Bwoe
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
I for one am confused with your description. You need to clarify what you are building and from where you'd like it to execute your shell script.

Are you developing a Objective-C app that you would like to execute a shell script? Are you developing an Applescript? Are you wanting to execute a script from Interface Builder? IB doesn't execute anything as it is used to build the interface.
 
OP
B
Joined
Feb 18, 2011
Messages
4
Reaction score
0
Points
1
Sorry if I wasn't clear enough, it's an applescript application built in Xcode (3.0 compatible). It was designed to run applescripts when buttons are pressed (this is where interface builder comes in), and I'd like to run a bash script instead of applescript when one of the buttons is pressed.
The workaround I have now is to have this button use an applescript to open the bash script like this.
Code:
on «event coVScliI» theObject
	try
		do shell script "open ~/Documents/MyBashScript.sh"
	end try
end «event coVScliI»

It works, but only if the bash script is in that specific directory. I'd like to have it as part of the app itself, instead of just opening a file elsewhere on the computer.
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
I've only done a little Applescript coding and never used Xcode for it. I don't know if the following is possible.

I'd look at adding the shell script to the 'Other Resources' folder in Xcode, and then looking for a function in Applescript that can refer to the location it was loaded from so that you could reference the script that would be in your app hierarchy.

To get the path to your current Applescript, I found the following maybe the answer;
Code:
set myAppFolder to ((path to me) as text)

Perhaps someone with more experience will speak up.
 
OP
B
Joined
Feb 18, 2011
Messages
4
Reaction score
0
Points
1
Thanks for the tips,
I had actually tried that, with the bash script in the Resources folder. Got it to work by changing the applescript to open "../../MyBashScript" instead of the full directory location, but it only works when Xcode is open!
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top