Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Testing Screen Size 2

Status
Not open for further replies.

Mag0007

MIS
Feb 15, 2005
829
US
Is there a way to tes the current screen size before a script is ran?

I want my script to run in full screen mode.

TIA!
 
Perhaps the LINES and COLUMNS environment variables ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I am using ksh, where can I find the LINES and COLUMNS variable?

But I *think* I know what you are trying to do....

good idea!
 
Another thought:
echo "My screen is $(tput lines) x $(tput cols)"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
okay in addition.

How can I check these certain values (cols and lines) before I execute my awk script? I prefer this check to be in awk.
 
something like this?

Code:
SCRLINES=$(tput lines)
SCRCOLS=$(tput cols)
export SCRLINES SCRCOLS
awk 'BEGIN{
 scrlines=ENVIRON["SCRLINES"]
 scrcols=ENVIRON["SCRCOLS"]
}
{
 # main awk code can use scrlines and scrcols variables
}'



HTH,

p5wizard
 
Hi

Why not just run the [tt]tput[/tt] from [tt]awk[/tt] ?
Code:
awk 'BEGIN{"tput lines" | getline my; "tput cols" | getline mx; print "My screen is " mx " x " my}'

Feherke.
 
feherke:

Nice, are the values of mx and my integers or string? if string, how can I convert them to integer?

It seems they are string, trying to do a numeric comparasion here.


if (mx < 20 || my < 20) print

does not seem to respond
 
either:
Code:
if (int(mx) < 20 || int(my) < 20) print

OR

Code:
if (mx+0 < 20 || my+0 < 20) print

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi

Mag0007 said:
Nice, are the values of mx and my integers or string?
If you want to be sure, dump them :
Code:
[blue]master #[/blue] awk --dump-variables 'BEGIN{"tput lines" | getline my; "tput cols" | getline mx}'
[blue]master #[/blue] grep "m[xy]" awkvars.out
mx: string ("167")
my: string ("55")
Mag0007 said:
if string, how can I convert them to integer?
With the [tt]strtonum()[/tt] function. Suitable to convert hexadecimals and octals too. But better choose one of vlad's advices.

Feherke.
 
This is my script to start Xnest (I've got a simular for rdesktop). It automaticly adjustes itself to the screen-size
Code:
#!/bin/sh
# Obtain current session values
#
declare -i width=$(xdpyinfo | grep -i dimension | awk '{ print $2 }' | awk 'BEGIN { FS = "x" } {print $1}')
declare -i heigt=$(xdpyinfo | grep -i dimension | awk '{ print $2 }' | awk 'BEGIN { FS = "x" } {print $2}')
# Compute new values (more from height, need the room for taksbars and so on)
#
(( width += -32 ))
(( heigt += -96 )) 
#
if [ -z ${1} ]
then
   echo "Geen parameter? Doe het dan maar met jezelf!"
   gastheer=localhost
else
   gastheer=${1}
fi
#
for s in {10,11,12,13,14,15,16,17,18,19} 
do
   if [ ! -e /tmp/.X${s}-lock ]
   then
      /usr/X11R6/bin/Xnest -name ${gastheer}:${s} -query ${gastheer} -once -geometry ${width}x${heigt} :${s}
      exit 0
   fi
done

As you can see, I added a negative number because I could not find how to "subtract" in a shell-script. Anyone?
 
Hi

Truusvlugindewind said:
As you can see, I added a negative number because I could not find how to "subtract" in a shell-script.
What ?
Code:
[blue]master #[/blue] i=15
[blue]master #[/blue] echo $i
15
[blue]master #[/blue] ((i-=1))
[blue]master #[/blue] echo $i
14
[blue]master #[/blue] let i-=2
[blue]master #[/blue] echo $i
12
[blue]master #[/blue] i=$((i-3))
[blue]master #[/blue] echo $i
9
[blue]master #[/blue] i=`expr $i - 4`
[blue]master #[/blue] echo $i
5
[blue]master #[/blue]i=`echo "$i-5" | bc`
[blue]master #[/blue] echo $i
0

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top