Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save and restore applications and layout

I'm looking for ways to reduce the wasted time spent to open all the applications needed, position windows, open urls/files/change directories/etc. before actual coding starts.

In the perfect world there would be 2 buttons marked 'SAVE STATE' and 'RESTORE STATE' per 'project'. The kind of feature you find in some games.

I'm on a mac and just spent afew hours banging my head with 'Automator' (which for some reason has problems to even open firefox from the dock) and then applescript (which gives me the feeling i'm in for a long ride).

Searching on the net led me to this script:

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

It does half the job (resize and position current windows) but falls apart on a multi-monitor multi-desktops setup. There is no contact info for the original author to ask for help or feedback.

Can anyone shed some light on saving and restoring applications and layout? It feels like such a common task that ought to have some helper utilities. The best I have is the 'sleep mode' but it seems I have to to do a full restart every other day and I have different applications and layout for different projects.

like image 883
zaf Avatar asked Sep 29 '10 17:09

zaf


People also ask

Is there a way to save Windows layout?

Simply place a shortcut to the program in your startup folder so it runs at boot. Open all the programs you want to save and place them where you want. Right-click the TAN Window Manager icon that will be in your tray and click 'Save Window Locations'. In the popup check the windows you want to save and click 'Save'.

How do I save a Windows size and position?

To save a window's size and position, use the hotkey Ctrl + Alt + S. Let's try it, open any program you want and use the shortcut to save its location.


1 Answers

This is a feature of Lion (Mac OS X 10.7) ... I wouldn't kill yourself over a feature Apple has seen the need for and has implemented rather seamlessly...

Apple feature page describing feature

like image 130
Alex Gray Avatar answered Sep 20 '22 02:09

Alex Gray