Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6644451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:10:07+00:00 2026-05-26T00:10:07+00:00

I’m looking for a Perl version of the code on this page: http://www.linuxquestions.org/questions/linux-general-1/how-to-bring-up-application-window-to-front-from-shell-script-83545/ So

  • 0

I’m looking for a Perl version of the code on this page:
http://www.linuxquestions.org/questions/linux-general-1/how-to-bring-up-application-window-to-front-from-shell-script-83545/

So as to enable me to bring a selected window to the front.

I’m on a linux box and am using xwininfo to select and get the window’s id(in hex).

Any help?

#!/usr/bin/perl
# v5.10.1 / linux
use strict;
use warnings;
use Shell;
use Tk;

# to enable you to pick a window to record +
my $result  =`xwininfo | grep -e Width -e Height -e Absolute -e "xwininfo: Window id:"`;

# get picked window's position (abs_x and abs_y)
# its width and heigh too, and make these divisible by 2 with no remainder (for even)
my ($abs_x, $abs_y, $window_width, $window_height, $windowid);
my @linesofoutput= $result=~/(.*?)\n/g; # needs checking to see if I'm getting the lines right with this?!

 foreach my $temp(@linesofoutput){

    if ($temp  =~ /^\s*Absolute upper-left X:/){ 
                 my  @words = split(/\s/, $temp);           # make an array out of the line, splitting on any whitespace character: space, tab, newline, etc
                 @words = grep(!/^$/, @words);            # remove empty elements.  check this(not, starting with, ending with)???                       
                # print "$words[0] \t $words[1] \t $words[2] \t $words[3]\n";  
                 $abs_x = $words[3];
                 # print "Got Absolute X:\t $abs_x\n";
             }
             elsif($temp  =~ /^\s*Absolute upper-left Y:/){
                   my  @words = split(/\s/, $temp);
                 @words = grep(!/^$/, @words);
                 $abs_y = $words[3];
             }
             elsif($temp  =~ /^\s*Width:/){
                my  @words = split(/\s/, $temp);           # make an array out of the line, splitting on any whitespace character: space, tab, newline, etc
                 @words = grep(!/^$/, @words);            # remove empty elements.  check this(not, starting with, ending with)???                        
                 #print "$words[0] \t $words[1]\n";  
                 $window_width = $words[1];
                 # print "Got width:\t  $window_width\n";
             }
             elsif($temp  =~ /^\s*Height:/){
                my  @words = split(/\s/, $temp);
                 @words = grep(!/^$/, @words);
                 $window_height = $words[1];
             }
             elsif($temp  =~ /^\s*xwininfo: Window id:/){
                my  @words = split(/\s/, $temp);
                 @words = grep(!/^$/, @words);
               # print "Window id: $words[3]\n";
                $windowid = $words[3];
             }
              else{
               #print "Something is wrong!\n";
               }
}

# make window_width and height divisible by 2 (ffmpeg requires even)
if ($window_width %2 != 0 ){ $window_width = $window_width -1;}
if ($window_height %2 != 0){ $window_height = $window_height -1;} # height problem...

# make a [ ] frame around the window # think about --- if the selected window were to be moved and/or resized???
my $offset = 3;  
my $lenght = 70;
my $colour = "#83857d"; # # maybe remove/fade the shadow a bit
my $mw = MainWindow->new(-background => "$colour",); 
my $abs_yM3 = $abs_y - $offset;    
my $abs_xM3 = $abs_x -   $offset;                                                                   
$mw->geometry("$lenght"."x"."1+$abs_xM3+$abs_yM3");        
$mw->resizable(0,0); 
$mw->overrideredirect(1);

my $mw2 = MainWindow->new(-background => "$colour",);                                                                   
$mw2->geometry("1"."x"."$lenght+$abs_xM3+$abs_yM3");     
$mw2->resizable(0,0); 
$mw2->overrideredirect(1);

my $abs_xPwless70P3 = $abs_x + $window_width - $lenght + $offset; 
my $abs_yPhP3 = $abs_y + $window_height + $offset;   
my $mw3 = MainWindow->new(-background => "$colour",);                                                                   
$mw3->geometry("$lenght"."x"."1+$abs_xPwless70P3+$abs_yPhP3");     
$mw3->resizable(0,0); 
$mw3->overrideredirect(1);

my $abs_xPwP3 = $abs_x + $window_width + $offset; 
my $abs_yPhless70P3 = $abs_y + $window_height -$lenght + $offset;   
my $mw4 = MainWindow->new(-background => "$colour",);                                                                   
$mw4->geometry("1"."x"."$lenght+$abs_xPwP3+$abs_yPhless70P3");     
$mw4->resizable(0,0); 
$mw4->overrideredirect(1);

 # bring the selected window to the front... but keep the frame above all?!

 # save dialog
 my $types = [
['mpg files',        '.mpg',          ],         # MPEG-2 is a high quality video standard used for DVD discs and Digital TV broadcasts. 
['avi files',        '.avi',          ],               # The AVI file created by Microsoft is the primary audio/video format for Windows platforms and may be compressed with a variety of codecs.
['mov files',        '.mov',          ],           # MOV - Apple QuickTime 
['All Files',        '*',             ],
];
## need a proper list of well known ones that ffmpeg can save to...

my $sfile = $mw->getSaveFile( # could look better... # position it
                                          -defaultextension => ".mpg",
                                          -initialdir => "/home/frank/Perl/screencaps", # standardise...
                                          -initialfile => "ScreenCast01",
                                          -title => "ScreenCast Capture file",
                                          -filetypes => $types
                                          ); 

&do_saveFileWithType($sfile) if defined $sfile;

sub do_saveFileWithType {
  my @InboundParameters = @_;
    print "This is what was passed:\t$InboundParameters[0]\n";

   # fix the "if the file is already there problem
   # show the file-extention with the "filename" & tie the filetype/defaultextension to the "Files of type:" selection...
   # all files problem...
 }

# 1. just capture the desktop/selected window -- no sound
my $result2 = ffmpeg ("-f x11grab", "-s $window_width"."x"."$window_height", "-r 25", "-i :0.0+$abs_x,$abs_y", " -sameq", " $sfile"); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:10:08+00:00Added an answer on May 26, 2026 at 12:10 am

    With X11::WMCtrl you can programmatically raise specific windows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.