2

I would like to add state of art of Unity launcher as template for creating minimal state of art of other users. I was found method how to add apps into template, but not method, how to extract settings of current user.

I am trying to ensure if just editing schema is enough to set display of logged user real name in panel indicator, as well.

  • 1
    I am not sure if I understand well. Is setting up a launcher in one user's account, and then "install" it for other users what you want to achieve? – Jacob Vlijm Sep 22 '14 at 18:30
  • Yes, I want to Is setting up a launcher in one user's account, and then "install" it for all other users of the system.. – Peter Fodrek Sep 24 '14 at 7:02
2

You can divide the Unity launcher's items in application launchers and other items; network related, mounted volumes and such. The best is to only copy the application launchers to other users, since the other ones can be user specific and / or vary during the process.

Also note that if you copy a launcher's content to another user, possible local .desktop files (in ~/.local/share/applications) of locally installed applications for example, will not appear in the other user's Unity launcher.

Reading the current launcher's content

Having said that, you can read the current launcher's content by the command:

gsettings get com.canonical.Unity.Launcher favorites

The output is a list of all items from your current Unity launcher.

Setting a new launcher's content

To set a new content for the launcher, the following command is used:

gsettings set com.canonical.Unity.Launcher favorites <list_of_items>

Using a script to copy the launcher to another user's account

If we use a script to fetch the launcher items of the first user, write the result to a file, then log into the another user's account to run the script again (together with the file) to set the content into other user's account, it can be done in no time. The script below is made to do both, depending on the argument you give it (see further below).

How to use

  • Copy the script below into an empty file, save it as copy_launcher.py
  • Open a terminal window in the "model user's" account, and run the script with the command:

    python3 /path/to/copy_launcher.py get
    

    The get -argument of the command makes the script create a text file: saved_launcher.txt, with the content of your current Unity launcher. The file is created in the same directory as where the script is located.

  • Copy both the script and the saved_launcher.txt file on (for example) an usb stick, but keep both files together in one and the same directory.
  • Log into other user's account, open a terminal and run the script by the command:

    python3 /path/to/copy_launcher.py set
    

    (mind the set argument)

The script

#!/usr/bin/env python

import subprocess
import os
import sys

command = sys.argv[1]

curr_dir = os.path.dirname(os.path.abspath(__file__))
datafile = curr_dir+"/saved_launcher.txt"

def get_current():
    get_current = subprocess.check_output(["gsettings", "get", "com.canonical.Unity.Launcher", "favorites"]).decode("utf-8")
    return (str([item for item in eval(get_current) if item.startswith("application://")]),
            [item for item in eval(get_current) if not item.startswith("application://")])

def write_saved():
    current_launcher = get_current()[0]
    with open(datafile, "w") as saved:
        saved.write(current_launcher)

def read_saved():
    with open(datafile, "r") as saved:
        return eval(saved.read())

def set_launcher():
    app_section = read_saved(); fixed_section = get_current()[1]
    new_launcher = str(app_section+fixed_section)
    subprocess.Popen(["gsettings", "set", "com.canonical.Unity.Launcher", "favorites", new_launcher ])


if command == "set":
    set_launcher()
elif command == "get":
    write_saved()

If you're done, you copied the Unity launcher from one user to another.

  • @PeterFodrek is this what you meant? please let me know if anything is unclear. – Jacob Vlijm Sep 25 '14 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.