0

I would like to have a clickable app that will open a terminal window, run the script:

defaults write com.apple.finder AppleShowAllFiles YES

and then close the terminal app. (and another to turn off the show all, same script with No at end). Automator seems to have a lot of potential, with not enough documentation that's easily found.

6
  • To those voting to close - How is this OT when this is not? - https://apple.stackexchange.com/questions/126660/alfred-how-to-get-alfred-to-run-a-terminal-command Jul 30, 2018 at 17:30
  • Why open in terminal at all. Why not just use the Automator action “run shell script”
    – Matt
    Jul 30, 2018 at 17:59
  • Matt - I don't know. Perhaps my question should have been "I have a need to frequently turn on/off the visibility of hidden files, what is the best way to simplify this process?" Jul 30, 2018 at 18:01
  • 2
    What version of OS X/macOS are you running? IIRC, Since Sierra all you have to do is press Space+Command+. to toggle hidden files. Jul 30, 2018 at 18:50
  • @JoeTaxpayer Please ask this on meta it is a good question and I would like to see the answer as I believe both should be closed.
    – JBis
    Jul 30, 2018 at 20:22

2 Answers 2

2

not enough documentation

Umm...Welcome to Automator - Apple Support

This is also a great link


There is so many different ways of doing what you want.

Option A: Shell Script (Does in background)

Option B: Open Terminal Window


A

Option 1: Pure AppleScript (Using /Applications/Utilities/Script Editor.app)

do shell script "defaults write com.apple.finder AppleShowAllFiles YES"

Option 2: Pure Automator

enter image description here

Option 3: Automator + AppleScript

enter image description here


B

Option 1: Pure AppleScript

tell application "Terminal"
    activate
    do script "defaults write com.apple.finder AppleShowAllFiles YES"
end tell

Option 2: Automator + AppleScript

(A3 with the in B1)


For the toggle hears the AppleScript Code to be used in any option of your choosing:

set a to (do shell script "defaults read com.apple.finder AppleShowAllFiles")
if a is "YES" then
    do shell script "defaults write com.apple.finder AppleShowAllFiles NO"
else
    do shell script "defaults write com.apple.finder AppleShowAllFiles YES"
end if

Export Options

Script Editor:

File>Export

  • File Format: Application

Automator:

Choose Application when creating a new document

enter image description here

1
  • Much thanks! It was worth the DV to get such a great answer. Yes, I looked at the support site, and it wasn't quite sinking in. Jul 30, 2018 at 17:22
2

I think using AppleScript would be a reasonable solution.

This code will do as you have requested.

tell application "Terminal"
    activate
    do script "defaults write com.apple.finder AppleShowAllFiles YES"
    quit
end tell

Clearly, all you would need to change is the YES to a NO to have it turn it off instead.

As for saving it as a clickable app, you could either simply paste, compile and export as an "Application" to do this straight from the AppleScript Editor itself.

However, if you are dead set on using Automator, open automator, create new document, select Application then click "choose". Next, search for "Run AppleScript", drag it into the main box. Now simply paste the AppleScript code from above where it indicates then press save. That's it! You can then repeat this process again and exchange YES for NO to get the two apps you need.

Hope that helped, please refer to Welcome to Automator for future reference.

1
  • I have just seen that @JBis has responded with a more detailed version of what I have suggested. Kind regards!
    – Tom
    Jul 30, 2018 at 17:24

You must log in to answer this question.

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