6

How can i create a dynamic quicklist for the home folder which adds all the bookmarks as quicklists (i heard it is possible via libunity) ?

Lincity
  • 25,371

2 Answers2

2

FYI The API is explained on the Ubuntu Wiki

Dynamic Quicklist entries

Quicklists may also be created and appended to the launcher. To create a quicklist 
a root node must first be created as a container, and then child nodes are added
to it. This final result may be packed into the launcher which is then 
shipped over the bus to Unity. Updates to the quicklist are also live.
Rather than describe the entire API, an example of using quicklist (as well as 
progress and count) is provided below using the vala bindings.

It is important to note that the main loop must be invoked for the program to 
actual work. Libunity requires the usage of the main loop as work may be done 
async. 

I have not seen an example of this yet. If I do I will add it here within an hour ;)

Dynamic quicklists did NOT work prior to unity - 3.8.8-0ubuntu1 due to a bug.

Rinzwind
  • 299,756
1

Here is a small shell script that updates your Home-Quicklist with all your bookmarks. No manual manipulation. It reads your bookmark file and creates the menu items from it. It also adds the "Root Filemanager" menu entry.

Screenshot of the quicklist in action

  1. Copy the script listed below into an empty file and put it in your scripts-folder (we will assume that is ~/bin/ and the script name you choose is unityhome.bash).
  2. Run the script once to add the entries:

    bash ~/bin/unityhome.bash
    
  3. Optionally you may have cron run the script for you every once in a while. To add it to cron, type the follwing command into a shell:

    crontab -e An editor will open. There add a line like:
    
    @reboot /bin/bash/ $HOME/bin/unityhome.bash > /dev/null 2>&1
    

    If you don't do this step, you'll have to run the script by hand every time you change your nautilus bookmarks if you want the quicklist updated.

  4. Changes only take effect on your next login or after you Alt+F2

    unity --replace So do that. *Note: Don't run `unity --replace`
    

    in a terminal. If you close that terminal, it will kill unity with it.*

  5. Enjoy and have a look at the similar script for gnome-terminal that parses your ssh bookmarks (in ~/.ssh/config).

Script: ------- Here is the script:

#!/bin/bash
# tabsize: 4, encoding: utf8
#
# © 2011 con-f-use@gmx.net. Use permitted under MIT license:
#     http://www.opensource.org/licenses/mit-license.php
# 
# CONTRIBUTORS: Chris Druif <cyber.druif@gmail.com>
#               Scott Severance <http://www.scottseverance.us/>
# 
# This script updates the unity quicklist menu for nautilus to

contain the user # bookmarks. The updates will have efect after unity is restarted (either on # the next login or by invoking 'unity --replace').

# location of template and unity bar launchers
nautempl="/usr/share/applications/nautilus-home.desktop"
target="$HOME/.local/share/applications/nautilus-home.desktop"
bookmarks="$HOME/.gtk-bookmarks"

# backup if file already exists
if [ -e "$target" ]; then
    echo "Creating backup of: $target."
    mv -n "$target" "$target.bak"
fi

# copy template
cp "$nautempl" "$target"

sed -i "s/\(OnlyShowIn=GNOME;\)/\1Unity;/" "$target"

echo "X-Ayatana-Desktop-Shortcuts=" >> $target

bmcount=0
while read bmline; do
    bmcount=$(($bmcount+1))     # number of current bookmark
    bmname=${bmline#*\ }        # name of the bookmark
    bmpath=${bmline%%\ *}       # path the bookmark leads to
    # deal with bookmarks that have no name
    if [ "$bmname" = "$bmpath" ]; then
        bmname=${bmpath##*/}
    fi
    # fix spaces in names and paths
    bmname="$(echo "$bmname" | sed 's/%20/ /g')"
    bmpath="$(echo "$bmpath" | sed 's/%20/ /g')"
    # extend shortcut list with current bookmark
    sed -i

"s/(X-Ayatana-Desktop-Shortcuts=.*)/\1Scg${bmcount};/" "$target" # write bookmark information cat - >> "$target" <

[Scg$bmcount Shortcut Group]
Name=$bmname
Exec=nautilus "$bmpath"
OnlyShowIn=Unity
EOF
done < "$bookmarks"

# Add a root file manager entry
sed -i "s/\(X-Ayatana-Desktop-Shortcuts=.*\)/\1RootFM;/" "$target"
cat - >> "$target" <<EOF

[RootFM Shortcut Group]
Name=Root
Exec=gksudo nautilus
OnlyShowIn=Unity
EOF

exit 0

Original Answer - Written by con-f-use

Lincity
  • 25,371