Sunday, May 10, 2020

HOWTO: Control Spotify and your MacOS volume from the command line

I use the following script called "~/.music.automation.sh" and load it from my "~/.bash_profile" with "source ~/.music.automation.sh".
---

# ~/.music.automation.sh

# Volume stuff
alias vol="osascript -e 'output volume of (get volume settings)'"
alias 0="osascript -e 'set Volume 0'"
alias 1="osascript -e 'set Volume 0.3'"
alias 2="osascript -e 'set Volume 0.6'"
alias 3="osascript -e 'set Volume 0.9'"
alias 4="osascript -e 'set Volume 1.2'"
alias 5="osascript -e 'set Volume 1.5'"
alias 6="osascript -e 'set Volume 1.8'"
alias 7="osascript -e 'set Volume 2.1'"
alias 8="osascript -e 'set Volume 2.4'"
alias 9="osascript -e 'set Volume 2.7'"
alias 10="osascript -e 'set Volume 3.0'"

# Synonyms for above
alias m="osascript -e 'set Volume 0'"


# Spotify stuff
alias next="osascript -e 'tell application \"spotify\" to next track'"
alias n="osascript -e 'tell application \"spotify\" to next track'"
alias previous="osascript -e 'tell application \"spotify\" to previous track'"
alias prev="osascript -e 'tell application \"spotify\" to previous track'"
alias p="osascript -e 'tell application \"spotify\" to previous track'"
alias pp="osascript -e 'tell application \"spotify\" to playpause'"



---
Then, I can SSH into MacOS and control the music remotely, from my phone for example.  Enjoy!


Thursday, April 16, 2020

HOWTO: Add loopback as a service

This can be easily done by adding an "ip" command to system startup with RHEL8 "systemctl".

1. Create a run script for ip to setup a loopback device on 192.168.10.1:

echo 'ip addr add 192.168.10.1/24 dev lo' >/usr/local/sbin/loopback2.sh
chmod 700 /usr/local/sbin/loopback2.sh


2. Create the service file:

vi /lib/systemd/system/loopback2.service
or
systemctl edit loopback2


2. Have it start as service with systemctl:


[Unit]
after=network

[Service]
ExecStart=/usr/local/sbin/loopback2.sh

[Install]
WantedBy=default.target


3. Enable and auto start:

systemctl enable loopback2.service
systemctl start loopback2.service


4. Confirm the setup:

ip addr
systemctl status loopback2

Monday, March 23, 2020

HOWTO: PostgresDB & pgAdmin4 setup on RHEL 8



---
dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

dnf install postgresql12-server postgresql12-contrib
---

yum install pgadmin4

/usr/pgadmin4/bin/./pgadmin4-web-setup.sh

service httpd start

Monday, March 16, 2020

Handy UNIX diff: Exclusive match

Super handy tool for selectively removing serial contents from a text file:

#!/bin/bash
# xdiff <new_file> <old_file>
# Exclusive diff - just show what's different from the first file
#       example: xdiff SYMBOLS.txt remove_symbols.txt >SYMBOLS2.out
diff -u $1 $2 | grep '^-[^-]' | sed 's/^-//'