I tried to create a script on OS X. I do something wrong. I want to execute 2 command:

defaults write com.apple.finder CreateDesktop -bool true


killall Finder

I saved and chmod the file but I got some errors:

/Users/max/Desktop/visible.command ; exit;
MacBook-Pro-de-Maxime:~ max$ /Users/max/Desktop/visible.command ; exit;
/Users/max/Desktop/visible.command: line 1: {rtf1ansiansicpg1252cocoartf1343cocoasubrtf160: command not found
/Users/max/Desktop/visible.command: line 2: syntax error near unexpected token `}'
/Users/max/Desktop/visible.command: line 2: `{\fonttbl\f0\fnil\fcharset0 Menlo-Regular;\f1\fmodern\fcharset0 Courier;}'


Thank you for your help!

  • obviously your script has "rtfiansiansicpg1252cocoartf1343cocoasubrtfr160" line at line 1. You should save your script a plain text file. Did you use TextEdit or Pages to save your command file? This could be the reason. – Rilakkuma Apr 6 '15 at 4:43

You have saved your file as a Rich Text Format file (.rtf)

In TextEdit.app

Open your file and use the Make Plain Text menu to change it to the correct format for coding.

Using anything other than plan text will mean that the file includes formatting code for styles and such that is visible to the shell layer but not to the user when viewing the file.

For example.

Rich Text Format file with the extension changed is still a rich text file

enter image description here

Reading it from the command line.

$ cat foo.command

{\fonttbl\f0\fnil\fcharset0 Menlo-Regular;}

\f0\fs26 \cf2 \cb3 \expnd0\expndtw0\kerning0
defaults write com.apple.finder \cf4 \expnd0\expndtw0\kerning0
CreateDesktop\cf2 \expnd0\expndtw0\kerning0
 -bool true}

Change to plain text and re saved.

enter image description here

enter image description here

Read from the command line.

$ cat foo.command
defaults write com.apple.finder CreateDesktop -bool true

( examples are for illustration only and not how to do the actual coding)


If you're just needing to run any two commands via a script, you can just create something like this, open a text editor and add:

echo foo && echo bar

Save it as foo.sh, then:

$ sh ./foo.sh

The && lets you have two commands being executed, one after another, or you can just put the commands on different lines.

In your case, replace echo foo with defaults write com.apple.finder CreateDesktop -bool true and replace echo bar with killall Finder. You'll probably need to run foo.sh with elevated priveleges using $ sudo sh ./foo.sh since you are changing defaults and killing pids.

You may have to make it executable, too:

chmod +x foo.sh

See https://stackoverflow.com/questions/8409946/how-do-i-make-this-file-sh-executable-via-double-click

  • Why the downvote? – Eric Dorsey Apr 6 '15 at 7:06
  • Sorry, I downvoted your answer. Obviously the topicstarter already knows that making a text file with commands will take him to the goal and asks why his actions did not work out. Your answer is not informative for this reason. Also, (sorry, being too picky) mentioning things like "pid" to someone who struggles to save a text file will not work out. – Rilakkuma Apr 6 '15 at 7:07
  • @Rilakkuma OP states: "How can i create a script" and "I want to execute 2 command" && executes two commands, and I gave an example of running it in a script. How is that NOT an answer to his question? – Eric Dorsey Apr 6 '15 at 7:15
  • Not going to argue over this, but there's one more line: "I saved and chmod the file but I got some errors". – Rilakkuma Apr 6 '15 at 7:18
  • So how does giving more examples of doing what the OP is trying to do not help him get to a solution? – Eric Dorsey Apr 6 '15 at 7:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .