GNOME Bugzilla – Bug 563553
Patch to add -p/--print-filename for printing the file's name & path to stdout
Last modified: 2014-05-02 17:26:35 UTC
Info: In order to enhance functionality between gnome-screenshot and other pieces of software at the command line level (think shell scripts), I propose to add a switch for the execution of the application which will allow users to receive the path and filename of their screenshot via stdout. Why: I've written a script which allows me to have the screenshots uploaded automatically to a server via SSH (scp) and the only way I could do it with the current functionality was to have the script run gnome-screenshot and then do a directory listing of a /Screenshots/tmp directory, upload the files & move it to the permanent location. How: I added a flag "-p" or "--print-filename" to the command-line options which sets a global variable in order to determine (upon success of try_to_save) whether the path & filename will be printed out. It is printed in the form of /dir/subdir/file -- in other words, the full path.
Created attachment 124089 [details] [review] Patch: Add an option for printing filename to command line Patch to add "-p" or "--print-filename" functions to gnome-screenshot in order to allow for ease of use when working in conjunction with other applications or scripts (think shell scripts).
Created attachment 124090 [details] [review] Add an option for printing filename to command line
Will create patch for latest stable & development versions tomorrow.
Hi Greg, and thanks for the patch. I think it would be good if your request could be merged with the one in bug 129768. It could work this way: - have a --path-to-screenshot (maybe with a better name) option which could either take a directory or a filename. - if the specified path is a directory, the screenshot tool will try to find a suitable default filename inside that directory, will create the new file and return the path on stdout. - if the specified path is a filename, you would try to save to that location, and if a file with the same name already exists you would error something out on stdout; otherwise you save to that location and return. The whole operation should be non-interactive, i.e. you should not display any dialogs, and the option should conflict with --interactive (i.e. you can't use --path-to-screenshot and --interactive together). Let me know if this is what you're looking for. I will accept a patch for implementing such behaviour and can help you with that if you like.
Well, my original idea was just to make it so you could continue to use the interactive dialog for actually saving the screenshot in question, but that is an excellent idea as well. I think that the option's name would be best as something like -o/--output-file. A couple of questions: If the output file exists, should we have it display an error, fail silently, or append something to the filename to make it unique? If it displays an error, should it be an error dialog or should it be something written to stderr/stdout? I would like to keep the -p/--print-filename option separate as well. See http://blog.nerdherdproductions.com/?p=30 for an example of the way I'm currently 'working around' the absence of the option and you can get an idea of why I believe this option is necessary. The reason I would like to keep it separate from -o/--output-file is because often I like to pick a place to save while using the PrtScr or Alt+PrtScr hotkey -- having it default to a location would not always be the best idea. Let me know what you think and I'll get these features implemented! Regards, Greg
I am going to go ahead and begin working on this probably tonight. Here are the switches I propose: -o, --output-dir -f, --output-file Output directory will, obviously, be the directory to which the file will be saved. It can also be omitted to use the currently saved directory from interactive mode or, if none exists, ~/Screenshots. This directory will also be used as a sort of 'failsafe' if the directory specified does not exist. Output file will work as one of two things: An absolute name for the file or, if the file already exists, a base-name for the file to which a number will be appended. It can also be omitted to use a default of 'Screenshot' for shots of the entire display or 'Screenshot-Windowname.png', just as the suggested names are now, for shots of individual windows. Obviously, the -o and -f flags are mutually exclusive to the -i, --interactive flag as they eliminate the need for an interactive mode. The -p,--print-filename flag, however, will be usable with both but completely optional for either -- though there is the option of making this the default behavior as it will not have any bearing on the outcome of the intended use of the program -- taking screenshots. If anyone has any ideas or comments, let me know! Otherwise, I'll get started and post a couple of different patches (2.20.x as well as the latest stable & development versions) for the program. Regards, Greg
As the --file option has been implemented to specify the filename to save to, I am closing this bug. Thanks for taking the time to report this bug. This particular bug has already been reported into our bug tracking system, but we are happy to tell you that the problem has already been fixed. It should be solved in the next software version. You may want to check for a software upgrade. *** This bug has been marked as a duplicate of bug 129768 ***