代码之家  ›  专栏  ›  技术社区  ›  zaf

保存和恢复应用程序和布局

  •  7
  • zaf  · 技术社区  · 14 年前

    在完美的世界里,每个“项目”都有2个标记为“保存状态”和“恢复状态”的按钮。你在一些游戏中发现的功能。

    我在一台mac电脑上,花了几个小时用“Automator”(由于某些原因,即使是在dock上打开firefox都有问题)和applescript(这让我感觉我要坐很长时间了)。

    http://snipt.net/Fotinakis/applescript-to-save-and-restore-window-positions/

    #!/usr/bin/osascript
    
    -- Usage:
    -- $ osacompile -o windowPositions.compiled.scpt windowPositions.scpt
    -- $ osascript windowPositions.compiled.scpt --save
    -- $ osascript windowPositions.compiled.scpt --restore
    
    -- Change this to be the list of windows you want to save/restore
    property affectedProcesses : {"Chrome", "Adium", "Eclipse", "Terminal"}
    property windowRecord : {}
    
    on run argv
     if (count of argv) is equal to 0 then
      log "Please specify one of --save or --restore."
      return
     end if
    
     tell application "System Events"
      if (item 1 of argv is equal to "--save") then
       set windowRecord to {}
       repeat with i from 1 to count affectedProcesses
        set end of windowRecord to {0, {}, {}}
       end repeat
       repeat with p from 1 to count affectedProcesses
        set processName to (item p of affectedProcesses)
        if exists process processName then
         log "Process '" & processName & "' exists"
         tell process processName
          set numWindows to count windows
          set item 1 of item p of windowRecord to numWindows
          repeat with i from 1 to numWindows
           set end of item 2 of item p of windowRecord to position of window i
           set end of item 3 of item p of windowRecord to size of window i
          end repeat
         end tell
        end if
       end repeat
      else
       repeat with p from 1 to count affectedProcesses
        set processName to (item p of affectedProcesses)
        if exists process processName then
         log "Process '" & processName & "' exists"
         tell process processName
          set numWindows to item 1 of item p of windowRecord
          repeat with i from 1 to numWindows
           set position of window i to (item i of item 2 of item p of windowRecord)
           set size of window i to (item i of item 3 of item p of windowRecord)
          end repeat
         end tell
        end if
       end repeat
      end if
     end tell
    end run
    

    1 回复  |  直到 14 年前
        1
  •  1
  •   Alex Gray    13 年前

    这是一个 feature of Lion (Mac OS X 10.7) ... 我不会为了一个苹果已经意识到需要并已经完美实现的功能而自杀。。。

    Apple feature page describing feature