• Script to Open Multiple (selected) files and position them on screen

    Home » Forums » AskWoody support » Windows » Windows – other » Script to Open Multiple (selected) files and position them on screen

    Author
    Topic
    #506108

    Script to Open Multiple (selected) files and position them on screen

    Good day,
    I want to be able to open a number of selected files (lets say 12 Excel files) with a batch file in such a way that each file (or workbook) is located on top of each other on the left side of the screen. In other words, I want to create the same effect as if I selected all the files, then open with say Excel, and then individually made each file full screen and pressing the Windows Key + Left Arrow (simultaneously pressing these keys) to locate it on the left halve of the visible screen. When closing one workbook, the next one behind it will become visible on the left halve of the screen, and so on.

    I hope this is at all possible.

    Thank you so much,
    Regards
    vanhunks

    Viewing 10 reply threads
    Author
    Replies
    • #1569524

      You can open multiple files easily, but placing them in a specific place on the screen may be more difficult. I expect you can move the programs around with AutoIt by simulating key presses.

      cheers, Paul

    • #1569552

      Thank you Paul, much appreciated.
      It looks like a very cool program.

      Kind Regards,
      vanhunks

      I hope there is somebody out there that can assist further.

    • #1570724

      Anybody with new ideas please?

      Regards,
      vanhunks

    • #1570759

      Vanhunks,

      I’m working on some PowerShell which looks promising but it will be a little while. :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1570793

      vanhunks,

      Ok, after a little googling I came up with some code and played around with it a bit and here is the result:

      With three apps open on screen #2:

      45026-Before

      After running the code:

      45027-after

      Program Zip File: 45028-Set-WorkEnv-V1

      So I’m running a 2 screen setup w/identical monitors both 1920×1080 resolution with Windows set up to “Extend the displays”, effectively one large monitor.

      That would lead you to think that by setting the Left edge of a window at 1921 it would position it on the second display, well it did get it close! As I found out you will have to diddle with the numbers a bit but once that’s done it the program will forever after put the windows where you want them.

      Here’s the code segment for setting the three apps above:

      Code:
      $SWSPArgs = @{AppName       = "powershell_ise"
                    AppWindWidth  = 1920
                    AppWindHeight = 1040
                    AppWindLeft   = 0 
                    AppWindTop    = 0}
      Set-WindowSizePosition @SWSPArgs
      
      $SWSPArgs = @{AppName       = "notepad++"
                    AppWindWidth  = 963 
                    AppWindHeight = 1040 
                    AppWindLeft   = 1915
                    AppWindTop    = 0}
      Set-WindowSizePosition @SWSPArgs
      
      $SWSPArgs = @{AppName       = "OUTLOOK"
                    AppWindWidth  = 965
                    AppWindHeight = 1040
                    AppWindLeft   = 1915+963 #Calculate based on Pos of Notepad++
                    AppWindTop    = 0}
      Set-WindowSizePosition @SWSPArgs
      

      As you can see the numbers aren’t exactly what you’d expect but pretty close.

      To get the AppName values you want to use Get-Process in a PowerShell window and spell, including CAPITALIZATION, exactly as reported.

      Code:
      PS> Get-Process
      
      Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id  SI ProcessName      
      -------  ------    -----      ----- -----   ------     --  -- -----------      
              
          116       7     1068       4952    57     0.00   2600   0 NitroPDFReader...
           65       6      696       3432    16     0.02   2500   0 nlssrv32         
          184      16     7848      18424   119     7.17   9164   1 [COLOR="#0000FF"]notepad++[/COLOR]        
          171       8     3500      12776    49     1.83   7800   0 OSPPSVC          
         2050      90    63324      91600   623     2.09   8940   1 [COLOR="#0000FF"]OUTLOOK[/COLOR]          
          630      86   287240     325636   609    10.55   8020   1 palemoon         
         1249      82   268104     151644  1134    56.81   3588   1 [COLOR="#0000FF"]powershell_ise[/COLOR]   
      

      The listing above is only partial but notice that OUTLOOOK is all caps, the code did not process the Outlook window when I initially typed it in as all lower case!

      I’ll probablly mess with this some more to add error checks, have PowerShell open the apps, and other options but for now it is functional and should do what you want.

      If you don’t know how to use PowerShell see this post items 1-3.

      See the comment at the top of the program file for how to setup a shortcut to run the program, you’ll have to adjust the program name as I didn’t change the original author’s comments at this point.

      Post back if you have any questions or suggestions.

      HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1570813

      vanhunks,

      Problem! For some reason this will not work properly outside of the PowerShell ISE!. When I tried to run it from a shortcut using the PowerShell CMD window it mispossitions the 2nd & 3rd windows to far to the right on the second screen. I’m working on it. Anyone have an idea why?

      :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1571158

      Hey Y’all,

      Sorry for the length of this post but I found this interesting and I thought others might, or might not, too.

      Well after much head scratching I think I have this figured out but I’m not really very happy about the answer.

      It seems that PowerShell ISE and PowerShell CMD work differently, at least when it comes to computing screen positions!

      I was mucking around with a lot of stuff and found that there is Screen Resolution and Effective Screen Resolution. You can see this several ways but I’ll show what Specccy reports:

      Code:
      Graphics
      		Monitor 1
      			Name	S27E510 on AMD Radeon HD 7500 Series
      			Current Resolution	1536x864 pixels
      			[COLOR="#0000CD"]Work Resolution	1536x824 pixels[/COLOR]
      			State	Enabled
      			Multiple displays	Extended, Primary, Enabled
      			[COLOR="#0000CD"]Monitor Width	1920
      			Monitor Height	1080[/COLOR]
      			Monitor BPP	32 bits per pixel
      			Monitor Frequency	60 Hz
      			Device	\.DISPLAY1Monitor0
      

      Notice that line that says Work Resolution. Well if you use those numbers to calculate the positioning of windows via a program running in the PowerShell Console (CMD version) the windows will size and position correctly. However if your are working in the PowerShell Integrated System Environment (ISE) then you need to use the Monitor Width & Height numbers. Don’t ask me why but using the exact same program running with different numbers produces the same result depending on where the program is run from. If you only use one set of numbers it will work correctly in one environment and not in the other. IMHO someone at MS should look into why this is so!

      All that aside, I now have a workable program that can be called from a shortcut to position (including opening programs if they are not already open or minimized) multiple programs across two identical monitors, should work on any number of monitors using the (extended option) as long as they are of the same geometry.

      I’ve broken the code into two programs, one calling the other, so that you can set up multiple configurations w/o repeating all the code.

      Function-Set-WindowsSizePosition.ps1 does all the heavy lifting of opening the program if it is not already open, Maximizing it if it is minimized, and then sizing and positioning the window in the desired location. There are two functions here one Set-WindowSizePosition and Set-WindowStyle. There should be no need to change anything in this program!

      Set-WorkEnv.ps1, you’ll want a renamed copy of this for each desired configuration ( e.g. Set-CodeDevEnv.ps1, Set-PresentationEnv.ps1, etc.) will setup the programs to be used and the sizes and locations of the windows then make the call to Function Set-WindowSizePosition to accomplish the task.

      You’ll need to adjust some of the parameters in Set-WorkEnv.ps1 for each work environment you with to establish and of course to make the settings match up with your hardware and software setup.

      $MSOfficeBase = the full path to your installation of MS Office (or Open Office if that is what you use).

      $AppList = @{} is a hashtable of all the programs you intend to use (you only need the ones for a given Environment, but you can include a bunch so copying the code will be easier your choice).

      $EffScrnWidth = the Effective, as discussed above, width of your monitors.
      $EffScrnHeight = the Effective height of your monitor (subtract the height of your task bar unless you auto hide it!).

      Don’t forget to adjust the dot sourcing of the Function file with your drive and path information, e.g.

      Code:
      . '[COLOR="#0000CD"]G:BEKDocsScripts[/COLOR]Function-Set-WindowSizePosition.ps1'

      In the sample file I’ve also included code to show you how to calculate screen position/size based on previously setup windows. A side benefit of doing it this way is the more you calculate the easier it is to move from machine to machine where you’d just have to reset the Effective screen variables.

      I’ve also included some debug output that you can enable by removing the comment from the calls to Set-WindowSizePosition, e.g.

      Code:
      Set-WindowSizePosition @SWSPArgs [COLOR="#0000CD"]#[/COLOR]-Verbose 4>&1 >> "$DebugFile"
      

      Remove the # and the output will automatically be written to the Root of your Documents folder in a file called WorkEnv.Log.
      It looks like this:

      Code:
      Excel
      App : Left 1536  Width 3072 Top 0  Height 824
      New : Left 0  Width 1536 Top 0  Height 826
      notepad++
      App : Left 1536  Width 2304 Top 0  Height 826
      New : Left 1536  Width 768 Top 0  Height 826
      OUTLOOK
      App : Left 1529  Width 3079 Top -7  Height 831
      New : Left 2304  Width 768 Top 0  Height 826
      

      It shows the position when opened (APP) and the (NEW) position.

      Program Zip File: 45041-Set-WorkEnv

      I hope this will solve Vanhunks problem and I’d be interested in any feedback anyone would wish to supply.

      HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1571198

      Wow! I am no expert, but this really looks impressive! Thank you so much RetiredGeek.

      Kind Regards,
      vanhunks

    • #1573257

      Hey Y’all,

      Here’s a little more I’ve learned in investigating this.

      The Effective Screen Resolution is the actual adapter resolution reduced by the magnification factory used in Display Settings Thus 1920×1080 reduces to 1586×864 at 125%, e.g. 864×1.25 = 1080!

      Oddly enough the PowerShell ISE always uses actual adapter resolution while PowerShell CMD uses the Effective resolution, or at least so I thought however then numbers below seem to indicate that the ISE is using some measurement system of it’s own! Possibly the infamous Microsoft Twit!

      Here are some measurements taken from PowerShell CMD with different display settings:

      Code:
      Excel Loaded on 2nd screen Maximized
      Excel @100%  (1920x1080)
      Left  : 1913
      Top   : -7   (Due to Monitor Overscan)
      Width : 1934
      Height: 1047
      
      Excel @125%  (1586x864)
      Left  : 1529
      Top   : -7  (Due to Monitor Overscan)
      Width : 1550
      Height: 831
      

      Here are the measurements taked from PowerShell ISE:

      Code:
      Excel @100%  (1920x1080)
      Left  : 2391
      Top   : -9
      Width : 2418 
      Height: 1309
      
      Excel @125%  (1586x864)
      Left  : 1911
      Top   : -9
      Width : 1938 
      Height: 1039
      

      The moral of this story is be very careful with your development and testing if you are doing GUI stuff in PowerShell as you will get different results between the ISE and CMD versions of PS. I actually noticed this before with my CMsPCInfo program but I thought it was just my eyes but I guess I was actually seeing straight after all! 😆

      The one on the Left run from the PS ISE the one on the right run from the PS CMD! Remember it’s the exact same code!:
      45184-ISEvsCMD

      HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1573267

      Your eyes must be really bad if you attributed that much difference to them. 🙂

      cheers, Paul

    • #1573303

      Paul,

      That was before I had my cataracts fixed! 😆

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    Viewing 10 reply threads
    Reply To: Script to Open Multiple (selected) files and position them on screen

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: