2011-05-03 12 views
6

Tengo dos monitores configurados y estoy tratando de colocar la ventana de una aplicación en el segundo monitor, pero parece que nada de lo que hago funciona. Por ejemplo, estoy usando mi computadora portátil y la ventana de la terminal se maximiza en la pantalla. Luego conecto un monitor externo. Luego quiero ejecutar el AppleScript y hacer que la terminal maximice en el segundo monitor más grande.Posicionar una ventana con AppleScript usando monitores duales

Aquí es lo que tengo en este momento:

set monitorTwoPos to {1050, -600} 
set monitorTwoSze to {1200, 1920} 

tell application "Microsoft Outlook" 
    set position of window 1 to monitorTwoPos 
    set size of window 1 to monitorTwoSze 
end tell 

Aquí está el error que consigo:

 
/Users/vcutten/AppleScripts/SpacesWork.scpt:1291:1332: execution error: 
Microsoft Outlook got an error: Can’t make position of window 1 into type specifier. (-1700) 

Estoy bastante seguro de que sólo estoy usando posición de ajuste y ajuste de tamaño completamente equivocado :(Cuando utilicé los límites funciona como ...

Pregunta de bonificación: ¿Cómo puedo abrir las ventanas abiertas y obtener su tamaño? Gracias

Respuesta

2

¿Qué has probado?

Creo que para resolver esto necesitas calcular el tamaño de la pantalla y las coordenadas del segundo monitor. Por ejemplo, su monitor principal comienza en la posición {0,0}. Entonces, la posición inicial del segundo monitor tiene que ser algo diferente y debes encontrarlo. Afortunadamente, he escrito una herramienta que le dará las coordenadas iniciales y el tamaño de pantalla de sus monitores. Una vez que tienes el tamaño y la posición, es simple. Los eventos del sistema puede configurar el tamaño y la posición de una ventana por lo que podría hacer algo como esto ...

set monitorSize to {800, 600} 
set monitorPosition to {-800, 0} 

tell application "System Events" 
    tell process "Terminal" 
     set frontWindow to first window 
     set position of frontWindow to monitorPosition 
     set size of frontWindow to monitorSize 
    end tell 
end tell 

lo tanto, desde el guión anterior que sólo tiene las variables de tamaño y posición. Puedes obtener mi herramienta here llamada hmscreens que te dará esas. Es posible que necesite hacer algún ajuste de las coordenadas dependiendo de si la pantalla se mide desde la esquina inferior izquierda o superior izquierda, pero eso es solo matemática simple.

Espero que ayude ...

+0

Gracias por la respuesta! Actualicé la pregunta con lo que me pediste ... Siento que simplemente no estoy usando la posición establecida correctamente :( – gdoubleod

0

Use límites en lugar de la posición, funciona. Puede obtener límites de la ventana como esta:

tell application "Microsoft Outlook" 
    get bounds of first window 
end tell 

respuesta a la pregunta extra:

tell application "Microsoft Outlook" 
    repeat with nextWindow in (get every window) 
     get bounds of nextWindow 
    end repeat 
end tell 

Si usted Respuestas abiertas pestaña en la parte inferior del editor de Applescript, verá todos consiguen resultados.

Espero que ayude.

1

Aquí hay una secuencia de comandos que se encarga de guardar y restaurar el tamaño y la posición de múltiples configuraciones de visualización. Puede tener algunos problemas con las aplicaciones de pantalla completa, pero parece funcionar bien.

-- allSettings is a list of records containing {width:? height:? apps:{{name:? pos:? size:?},...} 
-- for each display setup store the apps and their associated position and size 
property allSettings : {} 

-- create a variable for the current settings 
set currentSettings to {} 

display dialog "Restore or save window settings?" buttons {"Restore", "Save"} default button "Restore" 
set dialogResult to result 

tell application "Finder" 

    -- use the desktop bounds to determine display config 
    set desktopBounds to bounds of window of desktop 
    set desktopWidth to item 3 of desktopBounds 
    set desktopHeight to item 4 of desktopBounds 
    set desktopResolution to desktopWidth & "x" & desktopHeight 

    -- find the saved settings for the display config 
    repeat with i from 1 to (count of allSettings) 
     if (w of item i of allSettings is desktopWidth) and (h of item i of allSettings is desktopHeight) then 
      set currentSettings to item i of allSettings 
     end if 
    end repeat 

    if (count of currentSettings) is 0 then 
     -- add the current display settings to the stored settings 
     set currentSettings to {w:desktopWidth, h:desktopHeight, apps:{}} 
     set end of allSettings to currentSettings 
     --say "creating new config for " & desktopResolution 
    else 
     --say "found config for " & desktopResolution 
    end if 

end tell 

tell application "System Events" 

    if (button returned of dialogResult is "Save") then 
     say "saving" 
     repeat with p in every process 
      if background only of p is false then 
       tell application "System Events" to tell application process (name of p as string) 

        set appName to name of p 

        if (count of windows) > 0 then 
         set appSize to size of window 1 
         set appPosition to position of window 1 
        else 
         set appSize to 0 
         set appPosition to 0 
        end if 

        set appSettings to {} 

        repeat with i from 1 to (count of apps of currentSettings) 
         if name of item i of apps of currentSettings is name of p then 
          set appSettings to item i of apps of currentSettings 
         end if 
        end repeat 

        if (count of appSettings) is 0 then 
         set appSettings to {name:appName, position:appPosition, size:appSize} 
         set end of apps of currentSettings to appSettings 
        else 
         set position of appSettings to appPosition 
         set size of appSettings to appSize 
        end if 

       end tell 
      end if 
     end repeat 
    end if 

    if (button returned of dialogResult is "Restore") then 
     if (count of apps of currentSettings) is 0 then 
      say "no window settings were found" 
     else 
      say "restoring" 
     repeat with i from 1 to (count of apps of currentSettings) 
      set appSettings to item i of apps of currentSettings 
      set appName to (name of appSettings as string) 
      try 
       tell application "System Events" to tell application process appName 
        if (count of windows) > 0 then 
         set position of window 1 to position of appSettings 
         set size of window 1 to size of appSettings 
        end if 
       end tell 
      end try 
     end repeat 
     end if 
    end if 
end tell 

https://gist.github.com/cmackay/5863257

Cuestiones relacionadas