Posts

Pause a program which is using too much CPU

Sometimes your battery is running low and you need to pause a program without quitting it or force-quitting it, so that you can preserve battery but not lose the job that the program is doing. To do this,  Step 1. open a terminal (Utilities: Terminal) Step 2. type:  ps ax | grep -i "<program name>" so for example, if it's photoshop you need to pause, replace "<program name>" with "photoshop" Step 3. Next to the results on the far left you'll see a number, usually with 5 digits. E.g. 12345. Step 4. Type:  kill -STOP 12345 where 12345 are the numbers obtained in Step 2-3. Step 5. When you want to resume the program, type kill -CONT 12345 It should then continue to operate or run as usual without problems.

youtube-dl syntax

Technically, youtube-dl performs an illegal action which is to download or potentially download copyrighted videos. However, if you own the video, and want to take a backup copy, it is useful to do this. I did not write the below, when I find the source I will credit it. The general syntax is: youtube-dl -x --audio-format mp3 --audio-quality 320K youtube-dl will output in the current directory To list available formats youtube-dl --list-formats URL To download an entire user/channel youtube-dl -citw ytuser:<USER> or youtube-dl -citw URL To download all videos on a playlist youtube-dl -citw <PLAYLIST URL> To download a YouTube video as an MP3 youtube-dl -x --audio-format mp3 --audio-quality 320K <VIDEO_URL> To download best available video (mp4) and best available audio (m4a) and then merge them together youtube-dl -citw -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]' <VIDEO_URL> To set the output file title youtube-dl SOURCEURL --restrict-filenames --output ...

adding integers in BASH

 Addition in Bash is notoriously tricky and it almost never works as expected; it usually appends/joins two items as if they were strings regardless of whether they are in fact integers. This example works. Create a textfile containing lines of text, e.g.  a b c d Call it " list.txt ". Save this into a bash script and run it: #!/bin/bash counter=0 for i in `cat list.txt` ;  do   echo $counter   ((counter=counter+1)) done

non-interactive password change

 type (in BASH): echo -e " new_password  \n  new_password " | (passwd --stdin $USER) note the spaces around \n are there for readability, do not put them in.

managing virtualbox on the command line

You might want to manage virtualbox (the PC emulator) on the command line. The use case would be if you want to make a virtual machine (VM) on your machine which does not appear on-screen or which is started automatically. Suppose the virtual machine instance is called 'ubu'. The following commands will be useful. They are self-explanatory. The command VBoxManage should be in /Applications/VirtualBox/Contents/Resources/MacOS/ or similar. VBoxManage startvm "ubu" --type headless VBoxManage controlvm "ubu" pause --type headless VBoxManage controlvm "ubu" resume --type headless VBoxManage controlvm "ubu"  savestate VBoxManage controlvm "ubu" poweroff --type headless VBoxManage startvm "ubu" --type gui

Command line security tool on Mac to stop Root from damaging things

On the newer versions of Mac OS X (10.13 onwards, I think), there's a stricter permissions setting called "System Integrity" which stops even the root user from doing certain things on the command line, e.g. messing with the operating system itself. This can be very annoying if you are used to doing things as root. It can also stop you from installing some unix-type utilities. From the Apple menu, choose “Restart…” > “Restart“. Simultaneously press and hold the “Command” and “R” buttons. This will start you in Recovery Mode. Select “Utilities” > “Terminal“. Type one of the following, then press “Enter“: Disable System Integrity Protection:  csrutil disable Warning: your system is now less secure. If you get hacked, it was your decision to do this.

splitting a pdf

Suppose you want to take a 1000-page pdf called "input.pdf" and extract page 1, and 3 onwards, removing only page 2. Type the following:  pdftk  input.pdf  cat 1 3-end  output output.pdf