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.
Related
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
I already have finder showing hidden files by using
defaults write com.apple.finder AppleShowAllFiles YES
However, sublime text will not allow me to open hidden files still.
I'm looking for a programmatic way to accomplish this. So that I don't have to type a special key combination for each dialog.
Press "Command" + "Shift" + "." (dot) to show hidden files in the Mac OSX file chooser dialog.
You can also modify the folder_exclude_patterns setting. The default value for this is "folder_exclude_patterns": [".svn", ".git", ".hg", "CVS"]. In your case, you would want to make it "folder_exclude_patterns": [".svn", ".hg", "CVS"] You can access user settings by going to Preferences -> Settings - User
The defaults write command you entered only sets AppleShowAllFiles to true (or YES, they're equivalent) for Finder. To enable showing hidden files in all programs, enter
defaults write -g AppleShowAllFiles YES
The -g flag means "global", setting the AppleShowAllFiles attribute to true for all programs.
You'll have to restart Sublime after entering this command.
I am currently playing around with using defaults to change certain settings on my Mac (MacBook Pro 13-inch, 2019). I was trying to change the setting System Preferences > Dock > Prefer tabs when opening documents. After a bit of digging I found out that I can do this with the following command:
defaults write NSGlobalDomain AppleWindowTabbingMode -string '<always|manual|fullscreen>'
I was doing this so I could call it in a function I was writing before opening up a file in a particular application so the function always preferred opening in a new tab rather than a new window.
Note: that when I set the setting to Always in System Preference, opening a file with said application using open <file> -a <application> does indeed open the file in a new tab rather than a new window.
When testing, I went in to System Preferences and set the setting to Manually. Thereupon, I quit System Preferences and ran the following commands:
$ defaults read NSGlobalDomain AppleWindowTabbingMode
manual
$ defaults write NSGlobalDomain AppleWindowTabbingMode -string 'always'
$ defaults read NSGlobalDomain AppleWindowTabbingMode
always
$ open <file> -a <application>
When I run this, the file opens in a new window and not a new tab. In fact, it only opens in a new tab once I reopen System Preferences and open the Dock pane (running open <file> -a <application> opens in a new file now`).
It seems to me that Apple is overriding me in a sense but I can't figure out how to make this work. It seems odd that I need to manually interact with System Preferences (doesn't need to be the setting itself directly, but its pane) to get the effects of the setting change to take hold. Also, I found that if System Preferences is open while I am doing it, I need to quit System Preferences then navigate to the Dock pane for it to take effect.
Is there anyway to get around this? What is actually happening here that is preventing the effects of the settings change from taking hold?
I'm thinking of using the Mac's applescript to make a program that mutes the system when it is shutting down.
Though I'm new to applescript and I don't know how to use the IF-statement to determine if the system is shutting down. I've done some googling and I've found that the finder app is the app that is "controlling" the shutdown, but i don't know how to check if the state is "shut down". Can anybody assist me in this matter?
AppleScript has no direct mechanism for detecting a shutdown/logout.
It does have a mechanism for creating applications that can react to themselves being quit.
Thus, you can:
use AppleScript to create a stay-open application (.app bundle) with a standard on quit handler, in which you perform the desired action (
make sure that the application is launched on login - in the simpler case as a Login Item (via System Preferences, see below), or, with more flexibility but complexity, as a launch agent (see https://stackoverflow.com/a/22872222/45375).
Instructions:
Open Script Editor and open a new script window.
Paste the following code:
# This standard handler is called when the application quits.
on quit
# Mute the system volume.
# !! See caveat below.
set volume with output muted
continue quit # signal to the system that it's OK to quit
end quit
Save the script as a stay-open application:
with File Format Application
check Stay open after run handler
Open System Preferences > Users & Groups > Login Items, drag the newly saved *.app bundle into the list, and check the checkbox next to it, so as to make it launch hidden.
The final step is to hide the new application's Dock icon, as there's no reason for it to have one:
From Terminal, run the following:
defaults write /full/path/to/newApp.app/Contents/Info.plist LSUIElement 1
Note: You could use LSBackgroundOnly too, but the advantage of LSUIElement is that you can still display UI elements if you want to, such as for debugging.
Important: Substitute the full path of your new app for /full/path/to/newApp.app; the command will only work if you specify the full path to the Info.plist file.
To test, start the new app interactively, and make sure that no Dock icon appears. (You can quit the app via Activity Monitor).
CAVEAT: If the intent is to suppress the system startup sound, set volume with output muted has two drawbacks:
it will not work if headphones happened to be plugged at the time of shutdown
you will have to unmute the volume on startup (however, you could do that in an on on run handler in the same app).
Consider the alternative approach below, which requires admin privileges to set up and invokes nvram SystemAudioVolume=%80 with root privileges, which bypasses the above drawbacks.
You could run do shell script "nvram SystemAudioVolume=%80" user name "someAdminUsername" password "matchingAdminPassword" with administrator privileges from the above AppleScript app, but you'd have to hard-code the password, which is not advisable for security reasons.
Alternative approach, using a system-wide logout hook via com.apple.loginwindow.
There's a deprecated mechanism for running a script on logout that, however, still works as of OSX 10.10; given that there's no direct non-deprecated equivalent, it may continue to be supported.
Note that you do need admin privileges:
sudo defaults write com.apple.loginwindow LogoutHook <yourScript>
<yourScript> must be an executable, such as a shell script; note that the executable is run in the context of the root user.
In case you're thinking of muting the startup sound, invoke the following shell command from that script:
nvram SystemAudioVolume=%80 # to try this interactively, prepend `sudo `
This will mute sounds until after a reboot, effectively muting the startup sound, without keeping the sound muted.
Note that the nvram command requires root privileges, which are by definition in effect in a script run via the com.apple.loginwindow logout hook.; by contrast, to try the command interactively, use sudo nvram SystemAudioVolume=%80 - otherwise, you'll get the following, unhelpful error message: nvram: Error setting variable - 'SystemAudioVolume': (iokit/common) general error
Honestly, it is better to make a deterministic solution. What I mean is, is that you make a script that:
Mutes your computer.
Shuts it down.
Then you take your script and create an Automator service, that you can assign to some shortcut, to make it easier for you to use it. ctrl-opt-cmd-eject or something. :)
This is just how I would have solved it, if I have the need, it is short and sweet to make work, and should work reasonably well.
If you want to use the LogoutHook mentioned in #mklement0's answer.
You can use the normal Applescript command set volume with output muted.
You just need to add the osascript shebang to the top of the Applescript document
i.e
#!/usr/bin/osascript
set volume with output muted
And then save the file as applescript text file.
In the save dialogue use : file format: Text )
It will get the extension .applescript
Once it is saved, use Terminal.app to chmod the script as you would a normal shell script which in effect it is.
i.e
/bin/chmod +x foo.applescript
Then add it to the loginwindows LogoutHook.
sudo defaults write com.apple.loginwindow LogoutHook foo.applescript
I Know this is an old post but for anyone still looking how to do this(like I was) I have a simple method.
Before I started Scripting I created a new folder in my home folder called toolbar scripts.(this is optional)
With the desktop showing Finder click on Go >Utilities >Script Editor.
In the window that opens type in or copy and paste the code
set volume with output muted
tell application "finder"
shut down
end tell
Click on the last button above the script you added - it should be compile. If you cannot find that button then on the top click on Script >Compile
Click on File >Save in the save as I called mine shutdown and chose the script folder (this is optional)
Down the bottom of the dialog box at file format click on the arrow and change the format to application and click on save.
Open the folder you saved it in and drag the icon to the dock. Click on the icon you just put in the dock.
now if all is right this should mute the volume and shutdown the computer.
This will not shutdown the computer if you still have anything open.
Cheers
Peter
first, you should create a sound-off script (with terminal)
sudo nano /Library/Scripts/sound-off.sh
after filling it with these lines:
#!/bin/bash
osascript -e ‘set volume output muted 1’
and make a sound-on script like that
sudo nano /Library/Scripts/sound-on.sh
and fill it with:
#!/bin/bash
osascript -e ‘set volume 4’
then access them as executing files
sudo chmod u+x /Library/Scripts/sound-off.sh
sudo chmod u+x /Library/Scripts/sound-on.sh
and the last part is set them when the mac device is turn off and on:
sudo defaults write com.apple.loginwindow LogoutHook /Library/Scripts/sound-off.sh
sudo defaults write com.apple.loginwindow LoginHook /Library/Scripts/sound-on.sh
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!