All the balls are the same colour!
Credit: Derren Brown linked to Daniell Owengrub's blog which linked to SyFy which linked to David Novick (creator of image)
All the balls are the same colour!
Credit: Derren Brown linked to Daniell Owengrub's blog which linked to SyFy which linked to David Novick (creator of image)
I spent ages trying to get Orca to read selected text but there are a mind boggling number of options and while the GNOME (Ubuntu's default desktop manager) documentation is pretty good it never really worked. On further reading there seems to be some issue with Firefox and it was unclear if this had been resolved. I could get the Accessibility Options box to pop up using the short cut keys but none of the key bindings seemed to work for me. It's a shame because Orca comes with all sorts of goodies like reading mnemonics as text, reading camel case words as separate words (very handy if you read a lot of technical documentation!). Anyway, I couldn't get it to work so found another solution; not quite as feature rich but it does exactly what i want.
You need 2 pieces of software installed: something to read selected text (xsel
) and something to read it out (espeak
`) so install both of those:
sudo apt install espeak xsel
To test xsel
is working:
xsel
.
Your selected text should be returned by the command.To test espeak
is working just type:
echo "MrN is Ace" | espeak
and it should read out what is true ;)
Now we just need to put that together. Under GNOME (other Desktop managers may do it differently) we'll create a shortcut key binding to run our command on a magic key combo.
bash -c "xsel | sed -e :a -e '$!N;s/\n/ /;ta'| espeak"
CMD+[
on my Mac so Win+[
seemed simple on my PC.espeak
. So create another entry by hitting the + button.bash -c "kill `ps -au | grep '[0-9] espeak$' | awk '{print $2}'`"
That's it, it works in the text editor, browsers and everywhere else. Some browsers use CSS to stop you selecting the text but if you press F7
it'll switch on caret mode which lets you highlight text again. In applications (not web browsers) this is off my default but you should be able to toggle it with F7
too.
This is a tutorial and example of how Bash increases productivity.
We know that a Java archive is just a zip archive so it contains lots of files. We want to create our own index of what they contain so we are going to unpack them and create an index of their contents. Here is the situation.
$ ls -l
total 48616
-rwxr-xr-x 1 davidnewcomb staff 12952991 28 Nov 13:57 MRN.ear
-rwxr-xr-x 1 davidnewcomb staff 11642532 15 Sep 2017 MRN.war
-rwxr-xr-x 1 davidnewcomb staff 289943 21 May 2018 client.jar
Let's practice with one to start with. The Java comes with a jar
program to help you play with the file format. First we need a folder name:
file="MRN.ear"
dir=`echo $file | sed 's/\./_/'`
This writes a line with MRN.ear into the pipe, sed
takes each line and looks for a period followed by everything and replaces it with nothing. The result is assigned to a variable called dir
.
Next we are going to do the work using our new variable. First make a directory:
mkdir $dir
Then go into it:
mkdir $dir ; cd $dir
Next unpack the archive, we have to remember that we are actually a directory below the location of the archive so we need to prefix ../
to the path.
mkdir $dir ; cd $dir ; tar -xf ../$file
Finally we need to make the archive catalogue. So back up a directory level find
what we want:
mkdir $dir ; cd $dir ; tar -xf ../$file ; cd .. ; find $dir > $dir.find.txt
That'll work with one of them, but we have hundreds! No problem, we can just wrap it all in a loop.
for file in `ls`; do dir=`echo $file | sed 's/\./_/'` ; mkdir $dir ; cd $dir ; tar -xf ../$file ; cd .. ; find $dir > $dir.find.txt ; done
for
runs once for each item in a white space (or line break) separated list. We are running ls
to generate the list. Each item in the list will be assigned to $file
and then we just follow our normal path from before.
We have some choices now depending on what kind of resources you have. Bash has the amazing ability to run tasks in the background so waiting for a long command to complete just means you can do something else for a bit! You can push a task into the background by adding an ampersand to the end. For one command it's
echo "hello" &
or we can chain them together like so:
(cat /etc/hosts | grep 127) &
(cd bin ; ls) &
Let's add that to our command:
for file in `ls`; do (dir=`echo $file | sed 's/\./_/'` ; mkdir $dir ; cd $dir ; tar -xf ../$file ; cd .. ; find $dir > $dir.find.txt ) & done
There's no need for a semi-colon at the end because the closing parenthesis marks the end of the statement too so we can drop it.
It can be a bit tricky to write all of this first time and get it all right so there are various little tricks you can do while you are trying. Firstly write protect our starting files, we don't want to overwrite them by mistake:
chmod -w *
In the for loop I would create an expression that just produces one result. So you could try either of these:
for file in `ls | head -1`
for file in MRN.ear
Also you want to start from a clean slate each time, so remove anything with an underscore in it or anything ending with .txt
:
rm -rf *_* *.txt ; for file in `ls | head -1`
When we think we have got it right then remove the |head -1
and run it for real.
I've talked it through in terms of the mental thought processes behind building the command so it has taken a bit longer to go through it. When you work in this environment, it's not long before you start to think in terms of running commands together using the background with lots of piping to get what you want. It becomes second nature, you can do some incredible things. Sometimes those lines will go into a bigger bash program or used in a scheduled task, but most of the time, surprisingly, they are just thrown away because that thing you wanted to do is now done and you won't have to do it again. It's not even worth putting it in a file!!!
Further to my article Import Firefox Password Manager into Lastpass, I needed to do the same for the passwords stored on my mobile phone.
On my Android phone, load Chrome and go to Settings > Passwords. Click the 3-dot menu and then Export passwords. It'll ask for your password and confirmation then invite you to share the file. I used Bluetooth to transfer the file to my Mac. It named the file .com.google.Chrome.YmmVuO
where presumably the YmmVuO is the profile identifier. The dot at the front of the file name meant that it was invisible in Finder so it was back to the command line. Same procedure as before only we are converting The Chrome password CSV file which looks like this:
name,url,username,password
,android://nhugfghjkiu7y6grbh_yhg5f4d3d5fgthujo8hy7gytr_jhbggb==@com.example/,mrn@example.com,
example.com,https://example.com/login.php,mrn@example.com,armadillo
Follow the same steps as before and then apply the magic incantation:
d="Imported on `date`"
sed "s/^/$d,Imported,/" .com.google.Chrome.YmmVuO | \
sed "s/^$d,Imported,name/notes,folder,name/" \
> Chrome.YmnVuO_lastpass.csv
This converts it into the Lastpass CSV ready to import.
notes,folder,name,url,username,password
Imported on Thu 27 Jun 2019 17:03:29 BST,Imported,,android://nhugfghjkiu7y6grbh_yhg5f4d3d5fgthujo8hy7gytr_jhbggb==@com.example/,mrn@example.com,
Imported on Thu 27 Jun 2019 17:03:29 BST,Imported,example.com,https://example.com/login.php,mrn@example.com,armadillo
Now just follow the steps from Import CSV into Lastpass steps.
I had tried to jump on to the cloud password manager band wagon last year with Lastpass but it was a spectacular failure. I installed the Lastpass Firefox plugin, it asked me if I wanted to import all my existing usernames and passwords, then it identified everything to import, failed to import them into my Lastpass vault and deleted all the usernames and passwords from my Firefox Password Manager. Luckily I had backed up my Firefox profile before doing anything, phew!
The company I'm contracting with at the moment uses Lastpass so I have been using it there and thought it was about time I properly went for it again in MrN land. It wasn't as straightforward as I would have liked but the process I have declined is simple. Well simple if you are a developer with various GitHub related tools installed, various developer software packages installed and a familiarity with the Unix command line ;)
First up, sign up for a Lastpass:
https://lastpass.com/create-account.php
and install the Firefox plugin
https://addons.mozilla.org/en-US/firefox/addon/lastpass-password-manager/
It installed and on this occasion it didn't ask me if I wanted to import my passwords. I was secretly pleased as that had been the problem last time. Lastpass allowed you to import credentials from other well known manager types but not Firefox Password Manager. A bit of Google indicates that this is by design and part of Firefox's security model: no plugins of code gets access to the usernames and passwords, so it makes sense when you think about it.
The closest option is to export the credentials from Firefox as CSV and import them into Lastpass as a generic import. So here goes:
You've installed git and NodeJs right?
mrn@example git $ git clone https://github.com/kspearrin/ff-password-exporter.git
Cloning into 'ff-password-exporter'...
remote: Enumerating objects: 140, done.
remote: Total 140 (delta 0), reused 0 (delta 0), pack-reused 140
Receiving objects: 100% (140/140), 135.55 KiB | 351.00 KiB/s, done.
Resolving deltas: 100% (82/82), done.
Build the software
mrn@example git $ cd ff-password-exporter/
mrn@example ff-password-exporter (master) $ npm install
> fsevents@1.2.4 install /Users/mrn/Development/git/ff-password-exporter/node_modules/fsevents
> node install
[fsevents] Success: "/Users/mrn/Development/git/ff-password-exporter/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
> electron@3.0.6 postinstall /Users/mrn/Development/git/ff-password-exporter/node_modules/electron
> node install.js
and run it
mrn@example ff-password-exporter (master) $ npm run electron
> ff-password-exporter@0.0.0 electron /Users/mrn/Development/git/ff-password-exporter
> electron --inspect=5858 ./src --watch
Debugger listening on ws://127.0.0.1:5858/83577868-eb62-4f2e-9717-17c910bf901b
For help, see: https://nodejs.org/en/docs/inspector
Electron could not be found. No hard resets for you!
It launches a little graphical user interface asking you to direct it at a Firefox profile path. After saving you will get a CSV file is called firefox_logins_20190627000009.csv
(or whatever) which looks like this
hostname,username,password,timeCreated,timeLastUsed,timePasswordChanged,timesUsed
https://www.example.com,mrn@example.com,armadillo,1482355671960,1561490114251,1482355671960,7
We need to change that into a format that Lastpass can understand. This works on Unix based OSs. If you are using Windows then maybe you can borrow a Mac ;)
It's pretty much one line! Love you unix kiss kiss.
d="Imported on `date`"
cut -f1-3 -d, firefox_logins_20190627000009.csv | \
sed 's/\([^,]*\),/\1,\1,/' | \
sed 's/^hostname,hostname,/name,url,/' | \
sed 's>^http://>>' | \
sed 's>^https://>>' | \
sed 's/^/Imported,/' | \
sed 's/^Imported,name,url/folder,name,url/' | \
sed "s/^/$d,/" | \
sed "s/^$d,folder,/notes,folder,/" > firefox_logins_20190627000009_lastpass.csv
So stepping through the lines, take the first 3 column as separated by a comma from the file firefox_logins_20190627000009.csv
and we send that down the pipe. The file stream is read out and the first column is duplicated and given a the title of "name". The leading protocols are removed. (If anyone can join these together then please add a comment.) Next we add a new column at the from called "Imported" and change the title to "folder". Finally we add another column to the front called notes which gives us a marker specifying when the import took place (or by who) and change the column's title.
This will give us a file called firefox_logins_20190627000009_lastpass.csv
which looks like this:
notes,folder,name,url,username,password
Imported on Thu 27 Jun 2019 01:04:35 BST,imported,www.example.com,https://www.example.com,mrn@example.com,armadillo
Go to my vault in Lastpass Firefox plugin. On left at the bottom click through More Options... > Advanced > Import. Select Generic CSV File and click Import. Select the file firefox_logins_20190627000009_lastpass.csv
.
You will be forwarded to the Lastpass web site and shown a form with checkboxes next time all the passwords in the import file. Click Import All. A handy progress bar pops up and finishes with inviting you to open your Lastpass vault. All the passwords can be found in the Imported folder.
When you are happy with the transfer you can start deleting the credentials from Firefox. You can go through this procedure on each of your browsers. When you import more CSVs ensure that you check the merge duplicates to make sure you are not doubling up.