2011-05-03 16 views
6

Ho due monitor installati e sto provando a posizionare la finestra di un'applicazione nel secondo monitor, ma non sembra funzionare nulla. Ad esempio sto usando il mio portatile e la finestra del terminale è ingrandita sullo schermo. Quindi collego un monitor esterno. Quindi voglio eseguire il applescript e fare in modo che il terminale si ingrandisca sul secondo monitor più grande.Posizionamento di una finestra con AppleScript utilizzando due monitor

Ecco quello che ho in questo 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 

Ecco l'errore che ottengo:

 
/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) 

Sono abbastanza sicuro che sto usando solo di posizione e di impostare le dimensioni completamente sbagliato :(Quando ho usato bounds tipo di opere ...

Domanda bonus: Come posso passare in rassegna le finestre aperte e ottenere le loro dimensioni? Grazie!

risposta

2

Cosa hai provato?

Penso che per risolvere questo è necessario calcolare le dimensioni dello schermo e le coordinate del secondo monitor. Ad esempio, il monitor principale inizia alla posizione {0,0}. Quindi la posizione di partenza del secondo monitor deve essere qualcosa di diverso e devi trovarlo. Fortunatamente ho scritto uno strumento che ti fornirà sia le coordinate iniziali che le dimensioni dello schermo dei tuoi monitor. Una volta che hai le dimensioni e la posizione, allora è semplice. Gli eventi di sistema possono impostare la dimensione e la posizione di una finestra in modo che si possa fare qualcosa di simile ...

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 

Così dallo script sopra di voi solo bisogno le variabili di dimensioni e posizione. Puoi ottenere il mio strumento here chiamato hmscreen che ti darà quelli. Potrebbe essere necessario regolare alcune delle coordinate a seconda che lo schermo sia misurato dall'angolo in basso a sinistra o in alto a sinistra, ma è solo matematica semplice.

Mi auguro che aiuta ...

+0

Grazie per la risposta! Ho aggiornato la domanda con quello che hai chiesto ... Mi sento come se non stavo usando la posizione impostata correttamente :( – gdoubleod

0

Utilizzare limiti invece di posizione, funziona. È possibile ottenere limiti della finestra come questa:

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

Risposta alla domanda bonus:

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

Se si Risposte aperte scheda nella parte inferiore del editor di Applescript, vedrete tutti ottengono risultati.

Spero che aiuti.

1

Ecco uno script che gestisce salvataggio e il ripristino dimensioni e postion per molteplici configurazioni di visualizzazione. Potrebbe avere alcuni problemi con le app a schermo intero, ma sembra funzionare bene.

-- 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

Problemi correlati