PDA

View Full Version : Script for replacing a line in another script



BoogeyOfTheMan
July 8th, 2012, 05:31 PM
I'm looking to see if its possible to create a script that takes the path in the currently focused nautilus window and outputs it as a line in another script.

I have a script that opens the folder to the current audiobook I'm listening to open on boot, but since sometimes the book I'm listening to changes frquently, I'd like to just run a script to edit my startup script instead of editing it by hand.

Is this possible?

epicoder
July 8th, 2012, 08:01 PM
You can do this with a nautilus script and sed. Nautilus scripts have a number of context sensitive variables made available to them, such as $NAUTILUS_SCRIPT_CURRENT_URI for the current directory. So to change the variable var in the script ~/script.sh to the current directory, you would place this script in ~/.gnome2/nautilus-scripts:


#!/bin/sh
# The -i.bak creates a backup of the edited file with the extension .bak
sed -i.bak 's:var=.*$:var='$NAUTILUS_SCRIPT_CURRENT_URI':' ~/script.sh

BoogeyOfTheMan
July 10th, 2012, 11:53 PM
Ahh, ok. When I first read this a few days ago, it looked like gibbersih due to lack of sleep. Now I know what you mean, heh.

I just did a fresh install of 12.04 and its gonna take me a few days to get back around to setting my startup scripts again.