ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#!/bin/bash
# Variables
fileloc="/home/jerry/scripts/widget"
# Backup file first
cp $fileloc $fileloc.backup
widedit=`(yad --title="Linux Lite - Widget Editor" --borders=20 --text="All fileds <span font='Roboto Bold 12'>MUST</span> have a value:\n" --form \
--field="Gap X (0 - total monitor width span in pixels): ":NUM '!0..100000!1' \
--field="Gap Y (0 - total monitor height span in pixels): ":NUM '!0..100000!1' \
--field="Transparent (yes or no ):":CB yes!no! \
--button=gtk-apply:0)`
# Write to configuration file
echo $widedit | awk '{ sub(/gap_x/,"gap_x "$1); print }' >> $fileloc
echo $widedit | awk '{ sub(/gap_x/,"gap_x "$2); print }' >> $fileloc
echo $widedit | awk '{ sub(/gap_x/,"gap_x "$3); print }' >> $fileloc
exit 0
I'm wanting to have the line in /home/jerry/scripts/widget that shows gap_x 65 to read the value I input into the yad box, then overwrite the existing value in the widget file. At this point I am stuck. Thank you in advance.
1) What is the point of invoking yad in a subshell? Did you confuse old and new syntax for command substitution [backticks vs. $(...)]?
2) In Bash, I would quote 'yes!no!'.
3) yad will print values separated by vertical bars like 30|50|yes|, so you have to specify | as delimiter for awk. Alternatively, you could specify --separator=' ' as an option to yad.
4) The output of yad doesn't include the string gap_x, so trying to substitute it is pointless.
5) Moreover, I don't understand why you're doing it thrice.
There were some wording errors in my first post, now corrected. Thank you for your reply.
This is the conky widget file:
Code:
# Conky Widget
# Gap between borders of screen and text
# Same thing as passing -x at command line
gap_x 65
gap_y 25
# Use Xft?
use_xft yes
# Xft font when Xft is enabled
#xftfont Bitstream Vera Sans Mono:size=8
#xftfont Terminus:size=10
# Text alpha when using Xft
xftalpha 0.8
# Update interval in seconds
update_interval 1.0
# This is the number of times Conky will update before quitting.
# Set to zero to run forever.
total_run_times 0
# Create own window instead of using desktop (required in nautilus)
own_window yes
#own_window_colour grey
own_window_argb_visual yes
own_window_transparent yes
own_window_argb_value 0
own_window_type normal
own_window_class conky-semi
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
# Use a background image
background yes
# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes
# Minimum size of text area
minimum_size 300 200
# Maximum width of widget
maximum_width 310
# Draw shades?
draw_shades yes
# Draw outlines?
draw_outline no
# Draw borders around text
draw_borders no
draw_graph_borders yes
# Stippled borders?
#stippled_borders 8
# border margins
#border_margin 4
# border width
#border_width 1
# Default colors and also border colors
default_color white
color2 9fee62 # System is up to date
color3 ff4343 # Red - Number of Updates Available
default_shade_color black
default_outline_color white
# Text alignment, other possible values are commented
alignment bottom_right
# Subtract file system buffers from used memory?
no_buffers yes
# Set to yes if you want all text to be in uppercase
uppercase no
# Number of cpu samples to average
# set to 1 to disable averaging
cpu_avg_samples 2
# Number of net samples to average
# Set to 1 to disable averaging
#net_avg_samples 2
# Force UTF8? note that UTF8 support required XFT
override_utf8_locale yes
# Width and thickness of ${hr 2} bar separator
default_bar_size 150 5
# Lua rounded corners requirements
lua_load /etc/conky-lite/draw_bg.lua
lua_draw_hook_pre draw_bg
imlib_cache_size 0
# Distance of text from edge of widget
border_outer_margin 10
own_window_colour 000000
TEXT
${image /etc/conky-lite/logo.png -p 110,100}
###INFO###
${alignc}${font Noto Sans:bold:size=16}${color ffe082}${exec cat /etc/llver}${font}
${color}
${alignc}${color}${time %A, }${time %e %B %Y}
${color}
${color slate grey}${hr 2}
###SYSTEM###
${alignc}${font Noto Sans:bold:size=13}${color ffe082}System Information${font}
${color}
${color}CPU Usage: ${alignr}$cpu%
${color}Memory Total: ${color}${alignr}${memmax}
${color}Memory Used: ${color}${alignr}${mem}
${color}Logged in as: ${alignr}${color}$USER
${color}Firewall Status: ${alignr}${execpi 5 /etc/conky-lite/fwchk}
${color}
${color}${alignc}${exec /usr/bin/acpi | awk '{print $1,$3,$4,$5}'}
${color}
${color slate grey}${hr 2}
###UPDATES###
${alignc}${font Noto Sans:bold:size=13}${color ffe082}Update Status${font}
${color}
${alignc}${execpi 300 /etc/conky-lite/updates}
I want to overwrite the values below that are in the conky widget file, to whatever I input into the yad boxes, and leave the rest of the file intact.
Code:
gap_x 65
gap_y 25
own_window_transparent yes
Yes, I'm no bash guru, that is why I am here, for help and guidance. Cheers.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.