From 687df01a890512767bad5ea467d00a6b34bbba0a Mon Sep 17 00:00:00 2001 From: canavar Date: Sun, 10 Oct 2021 02:20:17 +0300 Subject: [PATCH 1/2] Updating readme reflecting script details Readme is updated with missing script format: a file with shebang chars and executable permissions --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index daa6b38..6e5ec07 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,17 @@ a new monitor, then you can use a `predetect` script to delay the execution. Write e.g. `sleep 1` into that file to make autorandr wait a second before running `xrandr`. +### Script format + +Each script you are placing under valid configuration folders must follow **bash/sh/yourshell** format. As an example; + +```bash +#!/bin/bash +notify-send -i display "Display profile" "$AUTORANDR_CURRENT_PROFILE" +``` + +And script must hold **executable** rights. ex: `chmod +x your_script` + #### Variables Some of autorandr's state is exposed as environment variables From eabc69f1ac9461895557211e4f42112352babf06 Mon Sep 17 00:00:00 2001 From: canavar Date: Sun, 10 Oct 2021 02:26:30 +0300 Subject: [PATCH 2/2] updating subprocess exception handling Subprocess exception handling is updated to print more information for the failed process call() reasons. This was particularly very useful when debugging why post/pre scripts are not executed properly. --- autorandr.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/autorandr.py b/autorandr.py index 25b0f53..e9174a4 100755 --- a/autorandr.py +++ b/autorandr.py @@ -1050,7 +1050,8 @@ def exec_scripts(profile_path, script_name, meta_information=None): if os.access(script, os.X_OK | os.F_OK): try: all_ok &= subprocess.call(script, env=env) != 0 - except: + except Exception as process_exception: + print(process_exception): raise AutorandrException("Failed to execute user command: %s" % (script,)) ran_scripts.add(script_name) @@ -1063,7 +1064,8 @@ def exec_scripts(profile_path, script_name, meta_information=None): if os.access(script, os.X_OK | os.F_OK): try: all_ok &= subprocess.call(script, env=env) != 0 - except: + except Exception as process_exception: + print(process_exception) raise AutorandrException("Failed to execute user command: %s" % (script,)) ran_scripts.add(check_name)