i am playing with YAD and want this command to save the edits to the text on the close
yad --text-info --editable --save --confirm-overwrite --show-uri --enable-spell --filename=editableFile.txt --width=400 --height=650
is this possible?
Related
I have a shell script that I run from Xcode to open the root folder in the Terminal. It works as expected when invoked by a function key in Xcode and opens a Terminal window pointing to the value of $SRCROOT as defined in Xcode and an alert with the expected message appears before that.
#! /bin/bash
osascript -e 'display dialog "message" with title "Hi"'
open -a Terminal "$SRCROOT"
Yet when I try to replace "message" to display the contents of $SRCROOT, the dialog doesn't display at all. I've tried all of the approaches listed in the solutions here: osascript using bash variable with a space
Using any of those approaches results in the alert not displaying at all.
I even tried to display the contents of $SRCROOT in a notification with various methods of escaping it but that just displays an empty notification.
Any ideas? TIA.
Save following in test.sh :
#!/usr/bin/env bash
SRCROOT=~/Developer/SwiftVC
osascript \
-e "on run(argv)" \
-e 'display dialog item 1 of argv with title "Hi"' \
-e "end" \
-- "$SRCROOT"
open -a Terminal "$SRCROOT"
and run it with :
chmod +x test.sh
./test.sh
I've been trying to get git-clone to provide output to a textbox in dialog. I tried something like this:
git clone github.com/CrazyWillBear/yes-replacement 2> /tmp/clone.log &
dialog --title "Cloning repo..." --textbox /tmp/clone.log 50 100
It doesn't work and usually displays nothing, writes to the terminal, or just the first line of the output. A loop doesn't work either, it creates some really funky problems.
The result I'm trying to get is this but with the entire output instead of just the first line: example
Use tee to write the output to a file, then use the tailbox feature on dialog to read it live.
git clone https://github.com/CrazyWillBear/pig --progress 2>&1 | tee -a /tmp/clone.$$ &> /dev/null &
dialog --title "Progress" --tailbox /tmp/clone.$$ 50 100
I am playing around with YAD dialogs in BASH and am having trouble with the button construction. I can't get a YAD button to call a function in the same script. Is there a way to do this?
My understanding is the if I use the following construction, pressing the button will call the command that follows the colon This example (which works) will open an instance of Firefox if a user clicks the Open Browser button:
yad --button="Open browser":firefox
I have a script with several BASH functions. I'd like a button press to call one of the functions. It doesn't. The following is a simple script that, when run, demonstrates the disappointing behavior:
#!/bin/bash,
click_one()
{
yad --center --text="Clicked the one"
}
click_two()
{
yad --center --text="Clicked the two"
}
cmd="yad --center --text=\"Click a button to see what happens\" \
--button=\"One\":click_one \
--button=\"Two\":2 \
--button=\"Date\":date \
--button=\"Exit\":99"
proceed=true
while $proceed; do
eval "$cmd"
exval=$?
case $exval in
2) click_two;;
99) proceed=false;;
esac
done
In the code above, button Date works as expected, calling the date command. Buttons Two and Exit work because I'm checking the exit value of the command and branching on its value. Sadly (for me), button One does nothing. I had hoped that clicking on button One would call the local function click_one. I would like to know if there's a way to format the YAD command so that the click_one function is called.
While the above code suggests a workaround using the exit value, my real goal is to apply a successful answer to a form button that, as far as I can figure out so far, doesn't return an exit value. In other words, the following also fails silently, but I'd like it to invoke function click_one:
yad --form --field="One":fbtn click_one
a possible way:
#!/bin/bash
click_one(){
yad --center --text="Clicked the one"
}
click_two(){
yad --center --text="Clicked the two"
}
export -f click_one click_two
yad \
--title "My Title" \
--center --text="Click a button to see what happens" \
--button="One":"bash -c click_one" \
--button="Two":"bash -c click_two" \
--button="Date":"date" \
--button="Exit":0
echo $?
Apparently not, it needs to be an actual command.
You could: put your functions in a separate file and as the command, launch bash, source that file, and call the function.
Here, I'm also restructuring your code to store the yad command in an array. This will make your script more robust:
# using an array makes the quoting a whole lot easier
cmd=(
yad --center --text="Click a button to see what happens"
--button="One":"bash -c 'source /path/to/functions.sh; click_one'"
--button="Two":2
--button="Date":date
--button="Exit":99
)
while true; do
"${cmd[#]}" # this is how to invoke the command from the array
exval=$?
case $exval in
2) click_two;;
99) break;;
esac
done
I'm using xdotool to open a Chromium browser and click a few things , but I'm wondering if I can get the source code of the live window it's using and dump it into a string to check if the source contains a particular string.
I know a wget can get me the source of a window , but what I want is the window that's already open as it will contain the string I want, but the wget option may not.
How can I do that?
If ctrl+U (show source) can be used, it will save your time, but if you need to inspect live HTML, try this xdotool script:
#!/usr/bin/env xdotool
search --sync --onlyvisible --name chrome
windowactivate --sync
key Ctrl+Shift+C
sleep 0.5
key Down
sleep 0.5
key ctrl+F
sleep 1
type "What you try to find"
key Return
Save as 'xdotool_script', then run it like you executing bash script
$ chmod +x xdotool_script
$ ./xdotool_script`
I use the following script to display a dialog in the bash shell:
#!/bin/bash
TFILE=/tmp/habitat_resp_`whoami`.$$
dialog --menu "Commander?" 20 50 10 \
1 "MySQL" \
2 "Apache" \
3 "Postfix" \
4 "Dovecot" \
5 "Owncloud" \
2> $TFILE
# get response
RESPONSE=$(cat $TFILE)
echo $RESPONSE
clear
The problem is, when I scroll up, i can still see the dialog in my scrollback. I want it like vi. I open my script and the dialog appears and if the script is over you cant see the dialog in scrollback.
How can this be achieved?
Regards
S.
Add the --keep-tite option, which tells dialog to use the "alternative screen", which doesn't participate in terminal scrollback. This produces some slightly annoying display artefacts, but possibly not as annoying as polluting your scrollback.