You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automator script to hide files gives "if: command not found" error

I am following the website https://www.lifewire.com/create-menu-item-to-show-hidden-files-2260155 to create a menue option that automatically hide and show fodlers and files.


I follow the instructions and copy the script. There seems to be some whitespace missing, which I insert. I end up with the code:


STATUS=`defaults read com.apple.finder AppleShowAllFiles` if [$STATUS == 1] then defaults write com.apple.finder AppleShowAllFiles -boolean FALSE else defaults write com.apple.finder AppleShowAllFiles -boolean TRUE fi killall Finder


I then find a folder I wish to hide, and choose it from the appropriate options, I then get this error (its in norwegain, but the top line translates to: "This error happened when trying to perform the action "Perform shell-procedure"":


Følgende feil oppsto under utføring av handlingen «Utfør shell-prosedyre»: «2019-07-18 12:06:00.516 defaults[6785:962964] 


The domain/default pair of (com.apple.finder, AppleShowAllFiles) does not exist


-: if: command not found»

MacBook Air 13", macOS 10.14

Posted on Jul 18, 2019 3:08 AM

Reply
Question marked as Top-ranking reply

Posted on Jul 18, 2019 5:56 AM

Ok, so with some googling I found out how to pass the folder as an input, so I managed to make a program with the simple code:


chflags hidden "$@"


Which does exactly what I wanted, thanks for the help!

Similar questions

4 replies

Jul 18, 2019 3:31 AM in response to Karl Wilhelm Norway

In the Mojave Finder, you only need to press shift+command+. (period) to toggle between hidden (dot files) or non-hidden filesystem views. This works for your Desktop, an open Finder window, or within application file choosers, where the application uses Apple's Cocoa frameworks in the design.


There simply is no need for the Automator service (Quick Action) offered in LIfeWire, when you can perform the keyboard shortcut quicker than navigating the Service menu. The LifeWire solution will not allow you to pick a particular file or folder and show/hide it, as that syntax applies to all content in your current Finder view.

Jul 18, 2019 5:35 AM in response to VikingOSX

Oh, then I somehow misunderstood the whole article, because I am indeed looking for a way to hide a folder. I see that the command you gave allows me to see or hide hidden items, which is neat, but not what I was looking for.


I know that the terminal command

chflags hidden


hides the item I give it, but I dont want to drag each folder into the terminal each time I want to hide something. I should maybe be able to create my own automator program that does this for me. I am not very experienced with it.

Automator script to hide files gives "if: command not found" error

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.