Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   OS X - Development and Darwin (http://www.mac-forums.com/forums/os-x-development-darwin/)
-   -   Help with a simple script (http://www.mac-forums.com/forums/os-x-development-darwin/300952-help-simple-script.html)

dgcrane 07-11-2013 07:38 PM

Help with a simple script
 
Hello,

I am having my first experience with a Mac for a media server I am trying to set up. Its going very well so far and working 98.5 % of the way I hoped for but I am hoping for some help with the last little bit.

I have been trying to make my first shell script to do what I am doing manually in the terminal. I assumed it could be like a bat file and just click on it and it would execute my three little lines :)

#!/bin/bash
export USEPADEVICE="XMOS USB 2.0 Audio Out"
export USEPAMAXSAMPLERATE=192000
open ~/Applications/SqueezePlay.app
exit

I am running a headless 10.6.8 and I have saved these lines a file called SqueezePlay.sh under my home directory.

Obviously, I got some problems, cause instead of executing, I get this :
Last login: Thu Jul 11 15:43:03 on ttys000

mac-mini:~ gena_mak$ ./SqueezePlay
./SqueezePlay: line 1: {rtf1ansiansicpg1252cocoartf1038cocoasubrtf360: command not found
./SqueezePlay: line 2: syntax error near unexpected token `}'
./SqueezePlay: line 2: `{\fonttbl\f0\fswiss\fcharset0 Helvetica;}'

I tried putting the same information into an applescript and that didn't work out very well either LOL

Thanks for any guidance you could give...

Darren

Raz0rEdge 07-11-2013 08:17 PM

A couple of things, you saved the file as "SqueezePlay.sh", but are executing "SqeeuzePlay"?? Secondly, did you set the shell script to be executable by typing "chmod 755 SqueezePlay.sh" and then try typing "./SqueezePlay.sh"??

dgcrane 07-11-2013 08:26 PM

Thank you for the reply... I think I did what you said previously, but to be sure, I did it again.

Last login: Thu Jul 11 15:52:11 on ttys000
mac-mini:~ gena_mak$ ls
Applications Downloads Music Sites
Desktop Library Pictures SqueezePlay.sh
Documents Movies Public
mac-mini:~ gena_mak$ chmod 755 SqueezePlay.sh
mac-mini:~ gena_mak$ ./squeezePlay.sh
./squeezePlay.sh: line 1: {rtf1ansiansicpg1252cocoartf1038cocoasubrtf360: command not found
./squeezePlay.sh: line 2: syntax error near unexpected token `}'
./squeezePlay.sh: line 2: `{\fonttbl\f0\fmodern\fcharset0 Courier;}'
mac-mini:~ gena_mak$

and this is what I get.....

Darren

Raz0rEdge 07-11-2013 09:29 PM

Darren,

Now I'm confused again..the file is called SqueezePlay.sh with a capital S, and you are executing squeezePlay.sh with a lowercase s. The command line is case sensitive..

What program did you use to create this script file? Can you add "set -x" after the "#!/bin/bash" to see if you get any useful debug messages?

dgcrane 07-11-2013 09:46 PM

oops, that was my fault... I didn't know is was case sensitive. I have tried to execute twice more :

./Last login: Thu Jul 11 20:20:47 on ttys000
mac-mini:~ gena_mak$ ./SqueezePlay.sh
./SqueezePlay.sh: line 1: {rtf1ansiansicpg1252cocoartf1038cocoasubrtf360: command not found
./SqueezePlay.sh: line 2: syntax error near unexpected token `}'
./SqueezePlay.sh: line 2: `{\fonttbl\f0\fmodern\fcharset0 Courier;}'

mac-mini:~ gena_mak$ ./SqueezePlay.sh
./SqueezePlay.sh: line 1: {rtf1ansiansicpg1252cocoartf1038cocoasubrtf360: command not found
./SqueezePlay.sh: line 2: syntax error near unexpected token `}'
./SqueezePlay.sh: line 2: `{\fonttbl\f0\fmodern\fcharset0 Courier;}'
mac-mini:~ gena_mak$

Once with set -x on the same line as #!/bin/bash and once below because I didn't know if it made a difference... results were the same. I believe its called textedit on the mac to create the file.

Darren

Raz0rEdge 07-11-2013 10:09 PM

Aha! You are not saving the file as a plain text file, you are saving it as a RTF file. I should've guessed with the "{rtf}" in your output..

OK, in TextEdit, with the file open choose Format->Make Plain Text. Then save the file and run it and you should have better results..:)

dgcrane 07-11-2013 10:09 PM

The problem was the editor I used... It added a bunch of junk in the file. I opened it up with a tool called editrocket and I could see the problem immediately.

all is working now and thanks for your effort and time.

Darren

Raz0rEdge 07-11-2013 10:16 PM

That's correct, shell scripts need to be plain text to be executed by the shell (Bash in this case), whereas TextEdit by default chooses to create/safe files as Rich Text which gives you the flexibility to add formatting to text which is great for some reasons but not for this..

So switching to Plain Text Mode would take care of the problem for you if you wish to use TextEdit again or if this editrocket program works, then that's fine too..


All times are GMT -4. The time now is 04:32 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.