Use Shell Script to write to plist Dictionary child Boolean - terminal

I'm trying to modify a system plist in an Platypus script-based app (Mac), though I have a feeling my question may have a more general answer.
The question is: What is the correct Terminal syntax for targeting and modifying the boolean child of a Dictionary key in a plist file?
I tried:
sudo defaults write /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist com.github.norio-nomura.SIMBL-Agent Disabled -bool false
but it doesn't like -bool with Disabled there..

I managed to solve it by using PlistBuddy instead. PlistBuddy is built into MacOS X 10.5 and above.
I could have used:
/usr/libexec/PlistBuddy -c "set :com.github.norio-nomura.SIMBL-Agent:Disabled bool" /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist
But it caused an error in the .pkg installer, so I used:
/usr/libexec/PlistBuddy -c "Delete :com.github.norio-nomura.SIMBL-Agent" /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist
.. and then:
/usr/libexec/PlistBuddy -c "Add :com.github.norio-nomura.SIMBL-Agent:Disabled bool" /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist
.. right after that which appears to be working.

PlistBuddy doesn't require the Type when SET a value
/usr/libexec/PlistBuddy -c "set :com.github.norio-nomura.SIMBL-Agent:Disabled true" /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist

Related

xcodebuild archive: set version number and build number

I'm writing a bash script to archive and export my project so I can send it to iTunes Connect. However, the documentation from the command line is a little confusing. I'm trying to figure out if there's a way to pass a parameter to the xcodebuild command that would set the version number and build number for that archive (similar to how you pass -scheme MyScheme when calling xcodebuild). Anyone done something like this before?
Thanks!
You can use this:
/usr/libexec/Plistbuddy -c "Set CFBundleVersion $SBUILD_NUMBER" "$PLIST"
/usr/libexec/Plistbuddy -c "Set CFBundleShortVersionString $BUNDLE_SHORT_VERSION" "$PLIST"
with PLIST is the path to your Info.plist

Set Default Shell in Cygwin

I've been using Cygwin for quite a while now. I now want to switch to fish from bash. Everyone is saying that you should use chsh -s /usr/bin/fish, but for some reason, chsh does not work for me. Trying to modify my Cygwin.bat file doesn't work either, and neither does changing my /etc/passwd file.
I really don't understand what's going on. Could someone please help me?
Try editing /etc/nsswitch.conf instead of /etc/passwd
Instead of creating a passwd file, which Cygwin recommends against1, you could edit /etc/nsswitch.conf. Add or edit the following line:
db_shell: /usr/bin/fish
The down/up side of this method is that, if you have multiple users, this change affects all of them. The up/up side is that it's dead simple. The only catch is that you have to restart Cygwin.
If you do use mkpasswd after this change, it will use your new default shell for all users that are allowed to log on.
References
1 The mkpasswd documentation says this:
Don't use this command to generate a local /etc/passwd file, unless you really need one. See the Cygwin User's Guide for more information.
I can't really find any solid reasoning in the user's guide, other than a mention that you'll have to regenerate the /etc/passwd and /etc/group files if your users and groups change, which I suppose is a decent enough reason. I can say that the process is somewhat error prone for newbies.
I randomly meet the same problem, and now I providing my solution for you.
0- Open cygwin by mintty.exe
1- Build passwd file manually (mkpasswd)
$mkpasswd > /etc/passwd
2- Change default shell in passwd file
$vim /etc/passwd
user:*:1976XX:1971XX:U-user\user,S-1-5-21-XXXX:/home/user:/bin/fish
3- Restart mintty.exe
There's an answer on SuperUser that is even simpler. Set the SHELL environment variable in Windows. Set it to your preferred shell (e.g. /bin/tcsh) and newly-launched shells should use it.
To set environment variables:
Go to the "System" control panel (right-click on the Start menu and select "System")
Click on "Advanced system settings" in the left-side column
From the "System Properties" window that pops up, click the "Environment Variables..." button
In either the "User variables" or "System variables" box (depending on whether you want the change to affect just yourself or all users), click the "New..." button.
Type "SHELL" in the "Variable name" box and the path (relative to the Cygwin file system) to your preferred shell in the "Variable value" box.
Click OK on the three open windows to save your changes.
I'm not sure how 'proper' of a solution this is, but I just added /usr/bin/zsh; exit to the bottom of my .bashrc file. You can substitute /usr/bin/zsh for the path to your shell of choice. It seems to work just fine so far.
If you're running Cygwin through ConEmu I found the easiest way is to replace commands line to run fish instead of default shell (Settings->Startup->Tasks):
""c:\cygwin64\bin\fish.exe" --login -i" (please change path to your cygwin folder accordingly)
I wanted to comment on the accepted answer, but not enough rep.
Regarding this method
$ mkpasswd > /etc/passwd
While this works to generate an /etc/passwd file, the odds are you're installing cygwin for yourself, and if your computer belongs to a domain, mkpasswd may run out and attempt to consume the entire domain user list. I had a 500MB+ /etc/passwd file from exactly this condition, and cygwin wouldn't even start until I deleted the file.
I strongly recommend, if using the mkpasswd route to use the -c switch, so it puts an entry in only for yourself.
$ mkpasswd -c > /etc/passwd
On a machine with a shared cygwin service (assuming you have write permissions)
$ mkpasswd -c >> /etc/passwd
I was trying to change my default shell in cygwin to zsh and I found parts of the answers
here helpful, but none of them gave a full solution. The best instructions I found were in the "installing zsh" instruction in the oh my zsh github repo by Robby Russel that you can find here
At the top of the page it has general instructions for installing zsh and then specific instructions for many different platforms. You can scroll down to the Cygwin section and follow the steps:
"The easiest way to change the default shell is to set your SHELL user environment variable. Search for "Edit Environment variables for your account" to bring up the environment variables window, create a new variable named "SHELL" and give it the value "/usr/bin/zsh/"."
(On Windows 7:
Press Windows key.
Start typing "environment".
When it appears, select "Edit environment variables for your account" and add the new variable as stated above.)
After I did this I closed and reopened my Cygwin shell window and tested that it worked with echo $SHELL. Expected result: /bin/zsh or similar.
Hope this helps!
Go to c:\cygwin or c:\cygwin64 (whatever is your cygwin home directory) and edit cygwin.bat. Instead of
bash --login -i
write, for example,
rem bash --login -i
tcsh -l
One simple way to do this is call tcsh at the end of .bashrc file
# x2=$(dirs +${cnt} 2>/dev/null)
# [[ $? -ne 0 ]] && return 0
# [[ ${x2:0:1} == '~' ]] && x2="${HOME}${x2:1}"
# if [[ "${x2}" == "${the_new_dir}" ]]; then
# popd -n +$cnt 2>/dev/null 1>/dev/null
# cnt=cnt-1
# fi
# done
#
# return 0
# }
#
# alias cd=cd_func
tcsh
alias g=gvim
source ~/.cshrc
source ~/.aliases

Tmux window title keeps renaming

Suddenly, both my screen/tmux started changing my windows' names after every command. They keep changing the name to the value of $PROMPT_COMMAND on every single action on the terminal, even after manually renaming them (by Ctrl+A A on screen or Ctrl+B on tmux).
On tmux I already tried to change the tmux.conf settings to disable window auto renaming off, but seems that it was ignored.
I am using bash without the standard /etc/bashrc configuration file. My distro is Fedora 18.
Add the following to your tmux config file:
set-option -g allow-rename off
Put this at the end of the .tmux.conf file:
set-window-option -g automatic-rename off
set-option -g allow-rename off
then reload the tmux config file (ctrl + b > : > source-file ~/.tmux.conf).
First, if l0b0's answer fixed your problem could you please mark it as a solution? Second, for those of use who stumble upon this question and are using fedora 19 this redhat bug report may be of interest. It seems like the default value of $PROMPT_COMMAND set by /etc/bashrc has been changed recently. I reverted to the previous behavior like this:
echo 'printf "\033]0;%s#%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"' > /etc/sysconfig/bash-prompt-screen
chmod a+rx /etc/sysconfig/bash-prompt-screen
Check whether your PS1 (plus PS2, PS3 or PS4 if those are set) is changing the title:
printf %q "$PS1" | grep -F '\\033'

How can I open Emacs on Mac OS X such that it is loaded with my $PATH?

I'm running Snow Leopard, and trying to run Emacs such that when I start it up, the output of (getenv "PATH") is the same as the output in Terminal.app of echo $PATH.
In other words, I want to start up Emacs from /Applications/Emacs.app and have it start with my $PATH. I haven't been able to figure out how to do this within emacs, or with how I start emacs up. So I've spent most of my effort trying to come up with a shell script that I can wrap with something like Platypus or Appify.
So the closest thing I have right now is:
echo MYPASSWD | sudo -S -u USERNAME -i nohup /Applications/Emacs.app/Contents/MacOS/Emacs > /dev/null &
which fails because it seems that nohup throws away my $PATH, despite the -i flag. The following does not throw away my PATH but open a superfluous Terminal.app:
echo MYPASSWD | sudo -S -u USERNAME -i open /Applications/Emacs.app/Contents/MacOS/Emacs > /dev/null &
I've tried running this through do shell script in an AppleScript, also to no avail.
Am I missing something basic? It doesn't seem like this should be hard. Thanks!
I wrote a little elisp a while ago to parse the output of env and apply it to the Emacs environment because I didn't want to maintain a plist. The code's at http://paste.lisp.org/display/111574.
GUI applications are not launched by a traditional shell and do not inherit environment variables from the usual places like .profile, .bash_profile, etc.
http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/EnvironmentVars.html%23//apple_ref/doc/uid/20002093-BCIJIJBH explains that ~/.MacOSX/environment.plist is the place you probably want to add your favorite equivalent of $PATH.
I ran into the same problem and here's how I worked around it. I created ~/.bashrc and populated it with:
source /etc/profile
source ~/.profile
You have to export the PATH to the location of the .app so it would be something like this
export PATH=$PATH:/path/to/the/program
That should allow you to just type EMACS and it will start up.

add a start up item via command line (mac)

How can I add a start up item via command line on a mac? From googling, I know you have to edit ~/Library/Preferences/com.apple.loginitems.plist using defaults write com.apple.loginitems [key] [value] but i'm not sure exactly which things to edit.
On Mac OS X 10.6 Snow Leopard, it is even simpler than that:
sudo launchctl submit -l name_of_startup_item -- command [args]
See man launchctl. On earlier versions, it is recommended that you create a Launch Daemon PLIST file and load/start it with launchctl rather than create a startup item... the startup items are the old school way.
defaults write loginwindow AutoLaunchedApplicationDictionary -array-add '{ "Path" = "/Applications/YourAppName.app"; "Hide" = 0; }'

Resources