LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Simple Nautilus shell script driving me nuts! (http://www.linuxquestions.org/questions/linux-software-2/simple-nautilus-shell-script-driving-me-nuts-4175441317/)

dryfly 12-13-2012 09:47 AM

Simple Nautilus shell script driving me nuts!
 
This Nautilus Shell-script does a simple video format conversion of a selected file and outputs the file to output.mp4:

#! /bin/bash
FILE=$(echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | sed q)
ffmpeg -i "$FILE" -sameq -s hd720 "output.mp4"

but if I try to incorporate the original filename into the output, it does nothing!!

#! /bin/bash
FILE=$(echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | sed q)
output="conv."$FILE".mp4"
ffmpeg -i "$FILE" -sameq -s hd720 "$output"

WHY???

bijo505 12-14-2012 03:31 AM

Hi,
Try to run the script in debugging mode, so you will get to know, where it is breaking

Eg: bash -bvx <scriptname>

-b Notify of job termination immediately.
-v Print shell input lines as they are read.
-x Print commands and their arguments as they are executed.

--
Thanks,
Bijo

dryfly 12-14-2012 06:55 AM

I hard coded the selected file into the script and ran it with debugging and it worked, but it won't work as a Nautilus shell script.

I modified the script slightly and added the mv line at the end to attempt to force a name change after the conversion is done. The conversion works OK but the mv line is never executed. I'm flummoxed!

#! /bin/bash

FILE=$(echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | sed q)

temp="temp.mp4"
output="conv."$FILE

ffmpeg -y -i "$FILE" -sameq -s hd720 "temp.mp4"

mv $temp $output

michaelk 12-14-2012 03:59 PM

$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS returns the full path to the file so your output file name would be

conv./path/to/file/name.ext.mp4

Slashes are illegal characters in file names which is why your script does not work. If you desire to have your file named as conv.filename.mp4 then you need to strip the path and filename first and recombine it so it looks like

/path/to/file/conv.base_file_name.mp4


http://linuxgazette.net/18/bash.html

dryfly 12-15-2012 06:27 AM

Quote:

Originally Posted by michaelk (Post 4849517)
$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS returns the full path to the file so your output file name would be

conv./path/to/file/name.ext.mp4

Doh! THAT must be why the variable has the word PATH in its name. I'm afraid that was too obvious for me. Here I was looking for some really obscure "feature" of bash. Many thnks for the link to the tutorial.

Geoff


All times are GMT -5. The time now is 05:06 PM.