Results 1 to 12 of 12
  1. #1
    New Lounger
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

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

    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

  2. #2
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,162
    Thanks
    47
    Thanked 976 Times in 906 Posts
    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

  3. #3
    New Lounger
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  4. #4
    New Lounger
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Anybody with new ideas please?

    Regards,
    vanhunks

  5. #5
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Vanhunks,

    I'm working on some PowerShell which looks promising but it will be a little while.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. #6
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    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:

    Before.png

    After running the code:

    after.png

    Program Zip File: Set-WorkEnv-V1.zip

    So I'm running a 2 screen setup w/identical monitors both 1920x1080 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 notepad++        
        171       8     3500      12776    49     1.83   7800   0 OSPPSVC          
       2050      90    63324      91600   623     2.09   8940   1 OUTLOOK          
        630      86   287240     325636   609    10.55   8020   1 palemoon         
       1249      82   268104     151644  1134    56.81   3588   1 powershell_ise
    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
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  7. #7
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    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?

    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  8. #8
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    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
    			Work Resolution	1536x824 pixels
    			State	Enabled
    			Multiple displays	Extended, Primary, Enabled
    			Monitor Width	1920
    			Monitor Height	1080
    			Monitor BPP	32 bits per pixel
    			Monitor Frequency	60 Hz
    			Device	\\.\DISPLAY1\Monitor0
    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:
    . 'G:\BEKDocs\Scripts\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 #-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: Set-WorkEnv.zip

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

    HTH
    Last edited by RetiredGeek; 2016-08-01 at 16:26.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  9. The Following User Says Thank You to RetiredGeek For This Useful Post:

    vanhunks (2016-07-22)

  10. #9
    New Lounger
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Wow! I am no expert, but this really looks impressive! Thank you so much RetiredGeek.

    Kind Regards,
    vanhunks

  11. #10
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    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 1920x1080 reduces to 1586x864 at 125%, e.g. 864x1.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!:
    ISEvsCMD.PNG

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  12. #11
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,162
    Thanks
    47
    Thanked 976 Times in 906 Posts
    Your eyes must be really bad if you attributed that much difference to them.

    cheers, Paul

  13. #12
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Paul,

    That was before I had my cataracts fixed!
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •