2

I have command in Terminal that I would like to put into an AppleScript file. Is this possible?

More info:
I'm using the following code to show hidden files. I type this on the command line in Terminal to make it work:

defaults write com.apple.finder AppleShowAllFiles -bool true
killAll Finder

I would like to convert this into an AppleScript file so I can double click on it and it will run sortof like a batch file in Windows.

UPDATE:
If there is a better option to use than a AppleScript file I would need to know how to run it from the command line in addition to double-clicking it.

1

2 Answers 2

5

Although it's quite easy to do, you don't need to convert this to AppleScript - just put the commands into a text file and save it on your Desktop as e.g. my_script.command (the .command suffix is the important part). Then make sure the file is executable:

$ chmod +x ~/Desktop/my_script.command

You now have a double-clickable executable script on your desktop.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Paul. I see. If it is not a scpt file then I also need to know is it possible to run this command from the command line?
Yes, you can just run my_script.command from the command line. It's just a shell script with a special name that the Finder recognises but you can run it like you would any other shell script.
OK. How would you run any other shell script? Like sh my_script.sh? I would rename my_script.command to my_script.sh? I was planning for AppleScript but this could work well if its the same.
You just invoke it by name, e.g. at the bash prompt: ~/Desktop/my_script.command, assuming you've saved it on the desktop.
3

If you really need to put it in an AppleScript:

do shell script "defaults write com.apple.finder AppleShowAllFiles -bool true"
do shell script "killall Finder"

..but note that this will not be as easy to execute from the command line as a shell script would be (see @Paul R's answer).

1 Comment

Thanks Gordon. I might need to go this route depending on the situation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.