Monday 17 May 2021

Quick and dirty guide to using shell scripts on Windows 10



PPM glitched using batch script and the sox flanger effect on Win 10

This guide comes out of the weekly Glitchlab sessions run by https://hacklab01.org/  and especially the work of Vedran Gligo , during the last session I realized that I needed to work out instructions for people using Windows 10 for some of the ideas I was presenting for working via bash scripts for manipulating images with an audio editor called sox. So Following Vedrans' instructions in that session to another participant I installed Windows 10 home on  a spare laptop, duplicated his steps  and wrote this guide ( with a few observations of my own and links to various programs mentioned - all done on Windows 10 home edition running the 20H2 update on a dual core Atom based Celeron N2840 ).

The bash script I used on Windows 10 to create the images above follows in the next blog post here - https://crash-stop.blogspot.com/2021/05/bash-script-for-sonification-images.html
 
1)Install notepad ++ as git bash asks to set a default editor in set up and notepad ++ is useful for making glitch art . get here - https://notepad-plus-plus.org/ 
 
2) Install git - bash ( for bash terminal as its better than windows powershell and includes some of of the basic linux/unix command line applications we will need - get git bash here - https://www.atlassian.com/git/tutorials/git-bash
 
 
*2023 Update - I had recommended installing sox via chocolatey but it seems that version of sox no longer works in the same way. The way I've found to install it for use via  git-bash  is to download the portable version from here ( choose sox-14.4.2-win32.zip) extract the contents then copy all the files to C:\Program Files\Git\usr\bin - you should now be able to access sox via git-bash
 
* Old instructions for sox 2021 
3) Install chocolatey , this is needed to install things like sox the command line audio editor we will use for sonification . To install chocolatey you will need to open win powershell as administrator ( quick guide here https://www.howtogeek.com/662611/9-ways-to-open-powershell-in-windows-10/ ) - so go to win icon in bottom left hand corner click on it and in search bar to the right type powershell it comes out top of list , right click and open as administrator then go here https://chocolatey.org/install and follow the install instructions carefully. ( you can copy and paste the commands from there into windows powershell) read prompts during installation carefully and answer Y when it asks. 
 
 
 
4) Having installed that keep powershell open and go here and install sox - https://community.chocolatey.org/packages/sox.portable ( the command to install is choco install sox.portable ) 
 
4a) Also maybe install imagemagickits handy for image manipulation via scripts but download the latest version from the imagemagick website as you dont have to mess about with paths etc to use it in gitbash https://imagemagick.org/script/download.php#windows
 
 5) How to run the script itself - for that we will use git bash but first use geany or notepad ++ to create a file called soundburger.sh (or whatever you want to call it) - make sure you add the .sh extension when you save it - that indicates to git bash its a shell script. Copy and paste in the script you want, I'm posting the one I'm working with in the next post  ( or write your own). Save that file , maybe in the folder where you are going to be working from ie where your pictures are. 
 
 6) Making the script executable - if you try to run the script without doing this it won’t work and will probably throw out an error message ‘saying permission denied’- open git bash in the folder where you saved the file ie go to that folder right click and then click on ‘git bash here’ that opens the git bash terminal then in that terminal type in chmod u+x whateveryoucalledyourscript.sh - it wont give any output unless there is a problem , unix/linux terminals are very precise and are case sensitive so pay attention to your typing. 
 
 7) now you can run the script by typing in the terminal ./whateveryoucalledyourscript.sh - sit back and watch your images being glitched ! 
 
Or you might just want to convert your images to a near raw format first , by near raw I mean uncompressed as these tend to survive glitch techniques quite well so jpg and png are basically out , I tend to work with ppm or tga or even bmp . We can use git-bash and imagemagick to do this outlined below.

7a) Get some pictures and change the format using  git-bash and imagemagick , open the folder where your pictures are, right click - open git bash here and type in this command  ( not including the start and end quote ) remembering that linux/unix command line is case sensitive so pay attention to your typing ' magick mogrify -format ppm *.JPG' - here I am telling imagemagick to change the format of all JPG (*.JPG) to ppm - if your jpegs are titled with lower case .jpg you would change the end part to *.jpg as imagemagick ( the magick at the beginning) wouldn't do anything because it literally won't see the lower case *.jpg if you have *.JPG cos that isn't what its looking for. Or you can use irfanview to batch convert and that might be easier.

8) look at your photos once you've glitched them, unlike Linux Windows 10 doesn't see or should I say give thumbnail views of file types it doesnt know like ppm , tga etc , to view the files you've just glitched u might want to think of an imageviewer like irfanview - find here https://www.irfanview.com/
 
I find its useful on Windows 10 to be able to see the file extensions of image files ( and most other files) so with an explorer window open ( explorer = the file manager in win 10 ) go to taskbar , file ,in the drop down window select options , this opens the folder options window click on view then uncheck hide extensions for known file types, it just makes it a hella lot easier to find files!

* I don't use windows generally I find linux just much simpler and faster so if you find errors in this guide please leave a comment or contact via mastodon @glitchbyte@mastodon.online

ikillerpulse ( requires tomato.py in working directory)

I've been working on this script for the last week or so. What does it do? It takes an input video/s,  converts to a format we can use f...