MacOS how to hide the folders and files located on the desktop - bash

I have folders and files on the desktop, I would like to make sure that when I take a screenshot or video recording of a program, the folders and files I have on the desktop are not seen.
Is there any command on the terminal that allows me to do this?
I need to hide everything only when I do the screen or the recording, and then return everything as before.
How can I do?

defaults write com.apple.finder CreateDesktop false && killall Finder
will hide all Files and Mounts, with
defaults write com.apple.finder CreateDesktop true && killall Finder
you can display them.
You have to invoke the commands from terminal
Tested wit Monterey 12.3

Related

How to see usr folder in mac when selecting files to open?

I need to open files in Xcode in the /usr but its invisible.
I already tried
defaults write com.apple.finder AppleShowAllFiles YES.
and restarted my finder but that didn't seem to work.
What should I do?
In the open file dialog box, you can hit Command-Shift-G and enter /usr in the Go To sheet.

Programmatically 'auto hide menubar' in El capitan

I really love the 'auto hide menubar' option in El Capitan, but sometimes I like it (private) sometimes I don't (work). Is there a way to show/hide it programmatically by changed it's value in a plist file? If so, in which plist file is that setting found? Any help is appreciated.
As answered by Rich Trouton on apple.stackexchange.com
Here's how you can set the menubar to be hidden and unhidden using defaults:
To hide:
defaults write NSGlobalDomain _HIHideMenuBar -bool true
To show:
defaults write NSGlobalDomain _HIHideMenuBar -bool false
Once run, logout and log back in. Alternatively, you can run the following command as the logged-in user to restart Finder and show the changes:
killall Finder
MacOs Sierra
As trevordmiller points out in the comment below, in Sierra it seems you have to close your terminal first to make the change have any effect.
As of 10.12.5 I am finding that #trevordmiller is only partially correct; Every application seems to need to be individually restarted to register the new setting. In other words, If I use:
defaults write NSGlobalDomain _HIHideMenuBar -bool false
killall Finder
this only shows the menu bar while Finder is active. To show it in other apps, I have to restart them. Killall Finder is not required in any way other than that it restarts Finder app and registers the setting for it. Same for restarting any terminal app.
From AppKit release notes:
NSApplication (New since WWDC Seed)
10.11 supports a new type of menubar behavior that hides the menubar during normal non-fullscreen interaction. The menubar shows itself
automatically when the mouse moves into a hot area at the top of each
display. When this mode is enabled, the
NSApplication.presentationOptions property will include the
NSApplicationPresentationAutoHideMenuBar value.
Prior to 10.11, the SetSystemUIMode API provided by HIToolbox, and the
setPresentationOptions API of NSApplication provided by AppKit, did
not allow explicitly enabling an auto-hiding menubar without also
hiding the Dock. -setPresentationOptions now allows the options to
contain AutoHideMenuBar without also including HideDock or
AutoHideDock. To ensure compatibility with existing applications, the
SetSystemUIMode API will only allow applications linked on 10.11 and
later to pass the combination of kUIModeNormal and
kUIOptionAutoShowMenuBar; if this combination is specified by an
application linked on Yosemite or earlier, the AutoShowMenuBar option
is ignored
You are looking for this bit. Flip it as you need.
typedef NS_OPTIONS(NSUInteger, NSApplicationPresentationOptions) {
/* Flags that comprise an application's presentationOptions */
NSApplicationPresentationAutoHideMenuBar = (1 << 2),
} NS_ENUM_AVAILABLE_MAC(10_6);
Too late. If it helps someone else, a shortcut could make it handy.
Open Automator -> Select Service -> Service receives selected text -> Select no input in any application -> Add Run Shell Script action -> Add the following lines.
bool=$(defaults read NSGlobalDomain _HIHideMenuBar)
if [ "$bool" == 0 ]; then
defaults write NSGlobalDomain _HIHideMenuBar -bool true
else
defaults write NSGlobalDomain _HIHideMenuBar -bool false
fi
Save it. (These steps creates a service that runs whenever the system boots.)
To give a shortcut,
Go to System Preferences -> KeyBoard -> Shortcuts -> Services -> Scroll to last to find General section -> Set a preferred shortcut for the service.
❯ /usr/bin/defaults write NSGlobalDomain _HIHideMenuBar -bool [true|false]
But you'll have to close instances of the Finder application, and fire it up again:
# `-g` don't bring app to foreground, `-a` specify app name
❯ killall Finder && open -ga /System/Library/CoreServices/Finder.app/
As a hotkey triggered script to toggle it on/off (hide/unhide):
if (( `/usr/bin/defaults read NSGlobalDomain _HIHideMenuBar` == 0 ));
then
/usr/bin/defaults write NSGlobalDomain _HIHideMenuBar -bool true \
&& killall Finder \
&& open -ga /System/Library/CoreServices/Finder.app/
else
/usr/bin/defaults write NSGlobalDomain _HIHideMenuBar -bool false \
&& killall Finder \
&& open -ga /System/Library/CoreServices/Finder.app/
fi
can be used with Alfred workflows, Hammerspoon, Keyboard maestro, Automator, etc.

Show system files / Show git ignore in osx

By default it is not possible to see .gitignore files in osx. What is command to reveal these files?
Open the terminal and type
on OS X 10.8:
defaults write com.apple.Finder AppleShowAllFiles TRUE
on OS X 10.9:
defaults write com.apple.finder AppleShowAllFiles TRUE
Then you must relaunch finder:
killall Finder
Any file name in OS X prefixed with a '.' is considered "hidden".
You can use the shortcut in Finder:
Command + Shift + .
It will show the hidden files.
To hide the files again, use the same shortcut.
⌘⇧. will toggle the AppleShowAllFiles setting.
This key combo will work from open/save dialogue boxes in all apps, not just the finder. Use this and you’ll never be confused when on someone else’s Mac or a new Mac, and you can avoid mucking around with defaults write.
I use the nemonic of “use a dot to show a dot file” to remember it, because of hidden dot files in unix.
if you just want to look at them you can always use the command line:
ls -al path/to/dir
If you want to always view all files from the finder you can do:
defaults write com.apple.Finder AppleShowAllFiles YES
If you just want to view a .gitignore from the finder you can:
chflags nohidden /path/to/dir/.gitignore
But youll have to call that command on every .gitignore its not global.
(more recent, for 10.10.2:)
The above commands didn't work for me. I'm using OSX Yosemite: 10.10.2.
This worked though:
defaults write com.apple.finder AppleShowAllFiles -boolean true;
killall Finder;
Source:
http://www.idownloadblog.com/2014/08/04/how-to-show-hidden-files-folders-finder-mac/
You can edit hidden file in terminal using this command
open -a TextEdit .gitignore
If you just want to view a .gitignore from the console just type "nano .gitignore" in that directory. This command "nano" simply opens any textfile in nano console environment for viewing or editing
In addition to the accepted answer, you can create an alias to easily show/hide the hidden files in Terminal. This is how I set it up (tested/working on macOS Mojave 10.14.1).
In my user directory I created a new file .custom_aliases and wrote this in:
# Show/hide files
alias showall='defaults write com.apple.finder AppleShowAllFiles -boolean true; killall Finder'
alias hideall='defaults write com.apple.finder AppleShowAllFiles -boolean false; killall Finder'
Next I opened .bash-profile (should also be in your user directory, if not just create it there) and added this to the top of the file:
# Load custom aliases
source ~/.custom_aliases
And that's it! Now whenever I need to view the hidden files I just type showall in Terminal and hideall when I'm done. You could also define the aliases directly in the .bash_profile, but I have some other stuff so I like to keep all the aliases together in a separate file.
Show hide file and folder on MacOs Mojave 10.14.4
Apply at Terminal
defaults write com.apple.finder AppleShowAllFiles -boolean true;
killall Finder;
It's possible you might just not have a .gitignore file. If you don't have one, you can create it like this:
>touch ~/.gitignore
And then edit it however you'd like. Git will automatically check this file, without any additional configuration!

how to put MySQL path in bash profile

I have to alter the bash profile in my mac in order to configure MYSQL but I don't know how to access the bash profile. The operating system of my mac was just replaced and the bash profile is no longer visible (it was visible but ghosted before). I'm using Mac 10.6.8 leopard (not lion)
Anyone know how I can get the path in my bash profile? I would also like a way to make the bash profile visible so I can open it anytime with a text editor.
I think the problem is that you're no longer showing hidden files (i.e., files beginning with a "."). To fix that, open up a Terminal prompt, and type the following:
defaults write com.apple.Finder AppleShowAllFiles TRUE
After that, you'll want to either reboot (not a bad idea if you haven't rebooted in awhile, in my opinion), or type:
killall Finder
To reset this option, just replace TRUE with FALSE.

Mac 'batchfile' script solution?

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
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>
Name the file .command or .sh.
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.
I used to use batch files but the pain was having to find the folder where the scripts where kept. This became a pain so now I use alias's which work from any location in terminal and do not require finding your script.
Of course you can use these together nicely.
To get started you need to access your bash_profile.
A bash profile is an invisible file that lives on your machine, I believe it is homeless without a particular location.
So how do you find it?
Well it either exists or it does not, so to access the file simply write:
sudo nano ~/.bash_profile
This command will either create it or open it up
Once inside, add the following lines:
alias showFiles='defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app'
alias hideFiles='defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app'
Thats it...
ctrl + O to save
ctrl + X to exit
And finally refresh the bash profile:
source ~/.bash_profile
How do you use the commands? Well now to show files, simply write: showFiles and to hide files just write: hideFiles... voila!
I use this to make life easier while using terminal. For instance to ssh to websites, or open help files, or to access mysql etc. etc.
Here are some further uses you may find useful:
alias goWebsite='open http://www,google.com'
alias goDoc='open -a TextEdit /users/myusername/documents/mydocument.txt'
alias goLocation='cd /applications/mamp/htdocs/workspaces/general/website.com/trunk'
alias sshToServer='ssh user#mysite.sitename.com'
Now all you need to do is type the alias from terminal and the command will execute.
Hope you find the above useful

Resources