tags:

views:

40

answers:

3

In Windows I would create a .bat file to run this script from my desktop, on my Mac how do I create something similar that can be run from the desktop to execute this:

 defaults write com.apple.finder AppleShowAllFiles TRUE
 killall Finder
+2  A: 

Name the file .command or .sh.

jtbandes
renaming to .command gives me the warning that I do not have enough permissions. I am admin though
BahaiResearch.com
@BahaiResearch.com I'm able to rename something to .command without entering a password. Maybe try making a copy of the file first?
jtbandes
@BahaiResearch.com Oh, make sure .command/.sh is the extension. Like myscript.command, not just .command.
jtbandes
You don't even have to do that -- it can have any extension if it has a shebang and has executable permissions.
Bryan Oakley
True, it's just easiest to give it an extension.
jtbandes
+2  A: 

Create a file with the following content

#!/bin/bash
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

From the terminal.app, run chmod o+x <filename> to make the file executable.

To run the file simply open the terminal.app and ./<filename>

Shoan
+1  A: 

Shoan's instructions for making a shell script will work fine, but you need to run it from within Terminal. If you add jtbandes suggestion of giving the filename a .command suffix (.sh doesn't work for me) the file becomes double-clickable in the Finder -- but it still opens a Terminal window, and leaves it open when it finishes. If you don't want to be bothered with this, there are a couple of ways of doing the job without any extraneous UI stuff:

1- Create an AppleScript in the AppleScript Editor (which is either /Applications/Utilities/AppleScript Editor.app or /Applications/AppleScript/Script Editor.app, depending on which version of OS X you have). Enter this as your script:

do shell script "defaults write com.apple.finder AppleShowAllFiles TRUE; killall Finder"

... and then save the script in Application format so it's double-clickable (if you save it as a "Script", double-clicking it will open the script editor instead).

2- Create an Automator workflow using /Applications/Automator. Use the Application template (again, to make it double-clickable), find the "Run Shell Script" action in the second column (it's a huge list, so I just type "shell" in the search field at the top) and drag it into the workflow space at the right. Make sure it's set to use a reasonable shell, paste in your commands, and save.

Gordon Davisson