3

Specifically, I want to toggle hotcorners on/off every time I start a steam game. But I have no knowledge of scripts of any kind. Any resources to learn this kind of stuff would be great.

Please tell me if this question is in the wrong place, I'll delete it.

5

If you just want the script, skip the explanation

Explanation

You'll have to learn at least an appropriate programming (/scripting) language, but then:

Introduction; dconf and gsettings
Most (if not all) of the settings, edited by Unity Tweak Tool edit the dconf database, in which many settings are stored. Editing the dconf database is best done via gsettings, which is in fact a cli-front end to the dconf database.

In your example, setting/toggling hotcorners can unfortunately only be done by editing the dconf database directly, because there is no SCHEMA available in gsettings for it.

Getting the current value
The hotcorners -plugin is set in:

/org/compiz/profiles/unity/plugins/core/show-desktop-edge

You can read the current state by the command:

dconf read /org/compiz/profiles/unity/plugins/core/show-desktop-edge

This will have an output in your case like (from your comment):

 '|BottomRight'

Setting a new value
To disable hotcorners, you need to run the command:

dconf write /org/compiz/profiles/unity/plugins/core/show-desktop-edge "''"

to (re-) enable hotcorners, with your previously set hotcorner:

dconf write /org/compiz/profiles/unity/plugins/core/show-desktop-edge "'|BottomRight'"

The anatomy of a toggle script

What the script (in general) should do:

  1. Test what is the current state A/B
    • If the current state is A -> set B
    • If the current state is B -> set A

The script

In the script the steps above are described in the comments:

#!/usr/bin/env python3
import subprocess

key = "/org/compiz/profiles/unity/plugins/core/show-desktop-edge"
val_on = "'|BottomRight'"

def test():
    # read the current setting
    return subprocess.check_output(["dconf", "read", key]).decode("utf-8").strip() == val_on

currstate = test()

if currstate == True:
    # if currently hotcorners are "on", set it to "''"
    newval = "''"
else:
    # if currently hotcorners are "off", set it to val_on
    newval = val_on

subprocess.Popen(["dconf", "write", key, str(newval)])

How to use

  1. Copy the script into an empty file, save it as toggle_hotcorners.py
  2. Test- run it from a terminal:

    python3 /path/to/toggle_hotcorners.py
    
  3. If all works fine, add it to a keyboard shortcut. Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

    python3 /path/to/toggle_hotcorners.py
    

How can I see what the Unity Tweak Tool is editing?

Not only for Unity Tweak Tool, but also to see what System Settings is editing, in many cases the following gives you usefull information:

  • Open a terminal, open Unity Tweak Tool
  • Run the command dconf watch / in the terminal
  • Change the value from GUI in Unity Tweak Tool

The output in the terminal changes:

![enter image description here

You can see what happens if I disable/enable hotcorners in Unity Tweak Tool.

| improve this answer | |
2

Tweaked @Jacob's script a little. First, using dconf watch / and switching hotcorners on/off in unity-tweak-tool to find out which variables(?) are being changed

  1. I have windows spread bound to bottom left corner, setting is in /org/compiz/profiles/unity/plugins/expo/expo-edge
  2. Also have workspace spread in bottom right corner, setting is in /org/compiz/profiles/unity/plugins/scale/initiate-edge

Thanks google and 2 day code workshop:

#!/usr/bin/env python3
import subprocess

key = "/org/compiz/profiles/unity/plugins/expo/expo-edge" #<-- this is for "show workspaces"
val_on = "'BottomRight'"

def test():
    # read the current setting
    # if one corner is on, other is also on and vice versa, no need to check both
    return subprocess.check_output(["dconf", "read", key]).decode("utf-8").strip() == val_on

currstate = test()

if currstate == True:
    # if currently hotcorners are "on", set it to "''"
    newval = "''"
    othercorner = "''"
else:
    # if currently hotcorners are "off", set it to val_on
    newval = val_on
    othercorner = "'BottomLeft'"

subprocess.Popen(["dconf", "write", key, str(newval)])

# this is for "windows spread"
subprocess.Popen(["dconf", "write", "/org/compiz/profiles/unity/plugins/scale/initiate-edge", str(othercorner)])

Volia, worked like a charm.

Really big thanks to @Jacob for giving me info and a basic script because I have no idea what dconf does or how to use python. Still don't. Where did you learn this anyway.

Seriously where do I learn this stuff.

| improve this answer | |
  • It's hard to say where things are learned, most of it just step by step and from being compulsive on gettings things done (and having fun with it) :) – Jacob Vlijm May 19 '16 at 20:48

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.