script to add icons to pinboard

interpretive language scripts


Moderator: Forum moderators

Post Reply
HerrBert
Posts: 356
Joined: Mon Jul 13, 2020 6:14 pm
Location: Germany, NRW
Has thanked: 18 times
Been thanked: 125 times

script to add icons to pinboard

Post by HerrBert »

From time to time i see questions in the forum about how to add an icon to the desktop.
If you know about ROX-Filer and its pinboard it is quite easy. Open /usr/share/applications, drag a .desktop file to the desktop and edit item from its right click menu.

Many users, who may be new to Puppy, do not know how ROXs pinboard works. Also, many new users may have heard about so called launchers or have already set them up in other Linux Distros. I can't recall i have ever seen the term launcher in Puppy Linux.

On the other hand, i was confused trying to add desktop icons to porteus' (IIRC it was mate) desktop. Tie!

So i made an attempt to write a script that will add a jwm menu item to ROX-Filer pinboard.
I found that menumanager would be a good basis to start with.

Code: Select all

#!/bin/bash
export TEXTDOMAIN=roxiconman

[ "$(ps | grep "ROX-Filer \-p" | grep -v "grep")" ] || exec /usr/lib/gtkdialog/box_ok "$(gettext "Error")" error "$(gettext "ROX-Filer is not running as desktop app")"

mkdir -p /tmp/roxiconman

build_list() {
	echo -n > /tmp/roxiconman/list
	CATEGORIES="$1"
	PTN="$(grep -o "Category>.*<" /etc/xdg/menus/puppy-${CATEGORIES,}.menu | sed 's/y>/ies=/;s/<$/|/' | tr -d '\n')"
	grep -liE "${PTN/%|}" /usr/share/applications/* > /tmp/roxiconman/list_all
	
	while read I; do
		[ "`grep -F 'NoDisplay=true' "$I"`" ] && continue
		IFS='=' read C1 NAME <<< "`grep "^Name\[${LANG::2}\]=" "$I"`"
		if [ ! "$NAME" ]; then
			IFS='=' read C1 NAME <<< "`grep -F 'Name=' "$I"`"
		fi
		[ ! "$NAME" ] && NAME="${I##*/}"
		echo "${NAME}|$I" >> /tmp/roxiconman/list
	done < /tmp/roxiconman/list_all
}

func_rox_addicon(){
	APP="$1"
	[ -z "$APP" ] && return
	LABEL="$(grep "$APP" /tmp/roxiconman/list | cut -f 1 -d '|')"
	PARAM="$(Xdialog --title "$(gettext "Add to desktop:")" --stdout --check "$(gettext "Locked")" --inputbox "${APP##*/}\n\n$(gettext "You can edit some options for the icon here.")\n\n$(gettext "Text displayed under the icon:")" 0 0 "${LABEL}")"
	[ -z "$PARAM" ] && return
	LABEL="${PARAM%$'\n'*}"
	LOCK="$(echo "${PARAM}" | sed '/checked/!d; s/^checked/true/; s/^unchecked/false/')"

	rox --RPC << EOF
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope">
 <env:Body xmlns="http://rox.sourceforge.net/SOAP/ROX-Filer">
  <PinboardAdd>
   <Path>${APP}</Path>
   <Label>${LABEL}</Label>
   <Locked>${LOCK}</Locked>
  </PinboardAdd>
 </env:Body>
</env:Envelope>
EOF
}

export -f build_list func_rox_addicon

build_list Desktop

export menuManager='
<window title="'$(gettext "ROX Icon Manager")'" icon-name="gtk-properties" default-width="550">
<vbox space-fill="true" space-expand="true">
  '"`/usr/lib/gtkdialog/xml_info fixed desktop.svg 60 "$(gettext "Add a Launcher icon to your desktop. Click on app to add it to desktop.")"`"'
  <vbox space-fill="true" space-expand="true">
    <frame '$(gettext "Menu items")'>
      <hbox height-request="350" space-fill="true" space-expand="true">
        <hbox space-expand="false" space-fill="false">
          <tree name="category" selected-row="0" exported_column="1" column-visible="true|false" space-expand="false" space-fill="false">
            <label>'$(gettext 'Category')'|command</label>
            <variable>CATEGORY</variable>
            <item stock="gtk-Desktop">'$(gettext 'Desktop')'|Desktop</item>
            <item stock="gtk-System">'$(gettext 'System')'|System</item>
            <item stock="gtk-Setup">'$(gettext 'Setup')'|Setup</item>
            <item stock="gtk-Utility">'$(gettext 'Utility')'|Utility</item>
            <item stock="gtk-Filesystem">'$(gettext 'Filesystem')'|Filesystem</item>
            <item stock="gtk-Graphic">'$(gettext 'Graphic')'|Graphic</item>
            <item stock="gtk-Document">'$(gettext 'Document')'|Document</item>
            <item stock="gtk-Business">'$(gettext 'Business')'|Business</item>
            <item stock="gtk-Personal">'$(gettext 'Personal')'|Personal</item>
            <item stock="gtk-Network">'$(gettext 'Network')'|Network</item>
            <item stock="gtk-Internet">'$(gettext 'Internet')'|Internet</item>
            <item stock="gtk-Multimedia">'$(gettext 'Multimedia')'|Multimedia</item>
            <item stock="gtk-Fun">'$(gettext 'Fun')'|Fun</item>
            <width>140</width><height>112</height>
            <action signal="changed">build_list $CATEGORY</action>
            <action signal="changed">refresh:LIST</action>
          </tree>
        </hbox>
        <hbox space-fill="true" space-expand="true">
          <tree hover-selection="true" exported_column="1" column-visible="true|false">
            <variable>LIST</variable>
            <label>'$(gettext "App")'|file</label>
            <input file>/tmp/roxiconman/list</input>
            <action signal="button-release-event">func_rox_addicon "$LIST"</action>
          </tree>
        </hbox>
      </hbox>
    </frame>
  </vbox>
 <hbox space-expand="false" space-fill="false">
    <button ok></button>
  </hbox>
 </vbox>
</window>'

ln -s /usr/local/lib/X11/pixmaps/*48.png /tmp/roxiconman 2>/dev/null
echo '
style "icon-style" {
	GtkStatusbar::shadow_type = GTK_SHADOW_NONE

	stock["gtk-Desktop"]    = {{ "x48.png", *, *, *}}
	stock["gtk-System"]	    = {{ "pc48.png", *, *, *}}
	stock["gtk-Setup"]      = {{ "configuration48.png", *, *, *}}
	stock["gtk-Utility"]    = {{ "utility48.png", *, *, *}}
	stock["gtk-Filesystem"] = {{ "folder48.png", *, *, *}}
	stock["gtk-Graphic"]    = {{ "paint48.png", *, *, *}}
	stock["gtk-Document"]   = {{ "word48.png", *, *, *}}
	stock["gtk-Business"]   = {{ "spread48.png", *, *, *}}
	stock["gtk-Personal"]   = {{ "date48.png", *, *, *}}
	stock["gtk-Network"]    = {{ "connect48.png", *, *, *}}
	stock["gtk-Internet"]   = {{ "www48.png", *, *, *}}
	stock["gtk-Multimedia"] = {{ "multimedia48.png", *, *, *}}
	stock["gtk-Fun"]        = {{ "games48.png", *, *, *}}
	stock["gtk-BB"]         = {{ "pet48.png", *, *, *}}
	}
class "GtkWidget" style "icon-style"' > /tmp/roxiconman/gtkrc

export GTK2_RC_FILES=/root/.gtkrc-2.0:/tmp/roxiconman/gtkrc
. /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
eval $(gtkdialog -p menuManager)

rm -r /tmp/roxiconman

Problem was to get the menu items in my LANG (de_DE.UTF-8). menumanager is a nice little app to add or remove apps from jwm menu, but if you have installed a langpack, many translated menu items no longer match appnames in menumanager.

Next problem is that categories in menumanager seem to be outdated (category network shows two apps). The script now gets the categories from /etc/xdg/menus/puppy-*.menu files.
Also .desktop files can have more than one category in a semi-colon separated list. Some menu items may not be displayed.

Another problem is, where to place the icon. By default rox seems to add an icon to pinboard automatically, if you don't specify the coordinates. But it also seems that rox uses a different icon grid step than the one you specify in rox options. But you need to drag the icon to a desired place anyway.

This is, what i made of it yet:

roxiconmanager.jpg
roxiconmanager.jpg (47.76 KiB) Viewed 1121 times

Thoughts about it:

1) will this be useful for anybody?
2) does it work for other languages in other Puppies?
3) does it make sense to spend hours on editing gtk2 apps nowadays???

Comments welcomed

EDIT:
I have rebuild the function build_list and removed attached script. (see code box above)

EDIT:
Updated code and .mo (de)

EDIT:
Messed up attachments... :oops:
.pet can be found here

Last edited by HerrBert on Thu Feb 03, 2022 8:30 am, edited 3 times in total.
User avatar
MochiMoppel
Posts: 1229
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 436 times

script to add icons to pinboard

Post by MochiMoppel »

HerrBert wrote: Fri Nov 05, 2021 12:30 pm

1) will this be useful for anybody?

I guess so. Nice and simple. Puppy users seem to love icons. I see a market :thumbup:

2) does it work for other languages in other Puppies?

Don't know.

3) does it make sense to spend hours on editing gtk2 apps nowadays???

Why not? Do you think that we will see a "GTK3 only" Puppy in the near future?
Apart from the stuff created for /tmp/roxiconman/gtkrc I see nothing gtk2ish in your code, and this stuff is IMO unnecessary. It's possible to add category icons without resorting to gtk stock icons, e.g. by using something like <item icon-name="x48">

Comments welcomed

2 small issues.
1) My Puppy has no /usr/lib/gtkdialog directory. No problem, the error dialog I'll never see anyway and the header I don't care for.
2) When accidentally clicking on an empty space in the App column without selecting an item (yes, that's possible) I get what you see in the screenshot. Can easily be fixed by making sure that the $LIST variable passed to func_rox_addicon is not empty.

Everything else works fine in Slacko 5.6
[Edit] see 4 posts below.

Screenshot.png
Screenshot.png (51.1 KiB) Viewed 1091 times
Last edited by MochiMoppel on Sun Nov 07, 2021 7:00 am, edited 1 time in total.
User avatar
wizard
Posts: 1969
Joined: Sun Aug 09, 2020 7:50 pm
Has thanked: 2620 times
Been thanked: 680 times

Re: script to add icons to pinboard

Post by wizard »

Your help text at the top of the app reads "Add a Launcher to your desktop. Click on app to add it to pinboard.". If I put on my "no nothing" hat, I ask what's a launcher? What's a pinboard" Since the user just wants to put an icon on the desktop, maybe "Add a Launcher icon to your desktop. Click on app to add it to the desktop." would be clearer.

I think we forget that new users coming from Windows or even other Linux distributions have trouble doing even the simplest task, this is one of them.

A comprehensive "How To" , with an icon on the desktop would go a long way to increase adoption. Here are few topics that come to mind:

-What applications are already installed & what can they do
-How to connect to the internet
-How to add an icon to the desktop
-How to install new applications & where can I find them
-How to set up a printer
-How to set up a soundcard
-How to manage files
-How to change desktop backgrounds
-How to change desktop icons

There are many more, we just have think about what a new user faces when adopting a new platform. We have to keep in mind the casual user just wants to run a few applications that let them accomplish their intended task. If everything they try just ends in frustration, they give up and return to what is familiar.

Thanks for your effort
wizard

Big pile of OLD computers

HerrBert
Posts: 356
Joined: Mon Jul 13, 2020 6:14 pm
Location: Germany, NRW
Has thanked: 18 times
Been thanked: 125 times

Re: script to add icons to pinboard

Post by HerrBert »

@MochiMoppel
I did not overcome the gtk ikon thing yet. As i understand the references, <item icon-name=x48.png> only applies to gtk icon themes. /usr/local/lib/X11/pixmaps/*.png icons don't apply to gtk icon themes.
The empty $LIST variable will be fixed.

@wizard

If I put on my "no nothing" hat, I ask what's a launcher? What's a pinboard" Since the user just wants to put an icon on the desktop, maybe "Add a Launcher icon to your desktop. Click on app to add it to the desktop." would be clearer.

Since i'm a nonnative english speaker, it's always a challenge to meat the sense of a translation.
But indeed, this hits the nail on his head. It was my intention to modify/edit/rewrite/(re)create this script to make it a simple task.
Funfact: my german translation in .mo file
msgid "Add a Launcher to your desktop. Click on app to add it to pinboard."
msgstr "Ein Icon auf dem Desktop anlegen. "
"Programm anklicken um es auf dem Desktop anzuzeigen."

retranslated via https://translate.google.com to:
"Create an icon on the desktop. "
"Click on the program to display it on the desktop"

There are many more, we just have think about what a new user faces when adopting a new platform. We have to keep in mind the casual user just wants to run a few applications that let them accomplish their intended task. If everything they try just ends in frustration, they give up and return to what is familiar.

Pardon my question, but why does no one of the devs take care about usability espescially for the new users?
And indeed this includes

-What applications are already installed & what can they do
-How to connect to the internet
-How to add an icon to the desktop
-How to install new applications & where can I find them
-How to set up a printer
-How to set up a soundcard
-How to manage files
-How to change desktop backgrounds
-How to change desktop icons

This is all questions i had, when i 'adopted' my first Puppy. I did a lot of searching and reading to find out how things work. But i would not expect that any user new to Puppy has the patience to do so.
Being referred to other forum posts is frustrating if you ask for help.
But why do so many new users have to ask for help? Because things are not selfexplaining in most cases.
To all devs: Please don't get me wrong. You all do a great job, but especially new users may feel lost in so much experience.

I'll update my code and make it available as a .pet or AppDir or something simple to use. Need to think about other options...

Thank's again for testing and improvements.
Very much appreciated...

User avatar
wizard
Posts: 1969
Joined: Sun Aug 09, 2020 7:50 pm
Has thanked: 2620 times
Been thanked: 680 times

Re: script to add icons to pinboard

Post by wizard »

But why do so many new users have to ask for help? Because things are not selfexplaining in most cases.

Your question is the one I ask myself. I see the same questions being ask many times in the forums. And as you said, they are questions I had as a new user. I started out with puppy version 1.04 and puppy developers and community have created lots of user friendly tools that other distributions don't have. I think if the puppy community were to create a knowledge base of "How to" documents, it could be made available for the dev's to include. At the very least it could be featured and referenced on the forum as a FAQ

Also, your English is very good.

wizard

Big pile of OLD computers

User avatar
MochiMoppel
Posts: 1229
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 436 times

script to add icons to pinboard

Post by MochiMoppel »

@HerrBert
Arguments to pass (for executables) does not work, for several reasons.

1) .desktop files are not executables nor are they programs (ROX-Filer manual: "For programs, you can specify extra arguments to be passed in"). If you add arguments to your generated pinboard icons you will receive an error when clicking on them.

2) Because arguments wouldn't work anyway, it's kind of fortunate that errors in your code prevent adding them.

ARGS="${PARAM#*/}; ARGS="{ARGS%$'\n'*} has doublequotes in the wrong place.
You don't need any doublequotes. Try ARGS=${PARAM#*/}; ARGS=${ARGS%$'\n'*}

<ARGS>${ARGS}</ARGS> should be <Args>${ARGS}</Args> . Tags are case sensitive.

Bottomline: Better forget the whole argument stuff ;)

HerrBert
Posts: 356
Joined: Mon Jul 13, 2020 6:14 pm
Location: Germany, NRW
Has thanked: 18 times
Been thanked: 125 times

Re: script to add icons to pinboard

Post by HerrBert »

@MochiMoppel
Thank you for pointing to the Arguments issue.
Since the script only adds menu items from the main menu, which is build from .desktop files, it doesn't make sense at all...

I updated the code in the first post.

Post Reply

Return to “Scripts”