LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Application-specific recent files pipe-menus for Openbox

Posted 01-10-2016 at 09:55 PM by the dsc
Updated 08-31-2017 at 03:42 PM by the dsc (improvement)

Here's an example for GIMP:

Code:
#!/bin/bash

printf "<?xml version=\"1.0\" encoding=\"UTF-8\"?><openbox_pipe_menu>"

# Instead of just "gimp" in the next line, it could even be a series of
# related programs, if you juggle between different applications with 
# these files. Such as "gimp\|inkscape\|krita\|mypaint"

grep -B 10 gimp ~/.local/share/recently-used.xbel | \ 
grep href | sed 's|.*file://||;s|" added.*||' | \ 
grep -i ".jpg\|.jpeg\|.png\|.gif\|.ora\|.kra\|.xcf\|.psd" | \
tac | while read file ; do

file="$(printf 'b' "${file///\\x}")" # url-decode the file

[ -f "$file" ] && # only prints the menu item if the file is still there
	(
	 label=$(basename "$file")
	echo "<item label=\"$label\"><action name=\"Execute\"><execute>mypaint &quot;$file&quot;</execute></action></item>" 
	)

done

printf "</openbox_pipe_menu>"
For other applications, the grep line must be adjusted accordingly, changing the grepped application name and the relevant file extensions. And the application in the "execute" line, of course.

Perhaps it could even be generalized so that the application is "$1" and the extensions are in "$2", and then the same script would be used with different parameters for different applications, but "on the fly".

Something like:

Code:
</item><menu id="libreoffice-writer-recent" label="recent" 
execute="/$USER/scripts/app-specific-recent.sh lowriter &quot;.ods\|.doc\|.rtf\|.xls\|etc&quot;"/>
But the "\|." also probably needs to be escaped, somehow.


If one doesn't care for the full paths appearing in the menus, or find it even to be helpful, then the script would be somewhat minimally faster, without the basename-generated label variable.


Edit: added a chek to see if the file still exists.

2 - the actual item apparently is better be echoed than printfed. Printf was resulting in a bug with some file name, presumably (I guess the name had "-B" on it, but apparently it's "%2B"), echo doesn't result in the same problem.
Posted in Uncategorized
Views 2410 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 09:13 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration