Skip to content

Instantly share code, notes, and snippets.

@rwky
Created October 5, 2011 20:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwky/1265596 to your computer and use it in GitHub Desktop.
Save rwky/1265596 to your computer and use it in GitHub Desktop.
Enables/disables application saved states on OSX Lion the right way
#!/bin/bash
#Copyright 2011 Rowan Wookey https://github.com/rwky
#Released under the MIT License http://www.opensource.org/licenses/MIT
#enabled/disables application saved states in osx lion
#most tools with guis seem to lock the "Saved State" folder in
#~/Library/Saved Application State/ however not all apps
#save states there (Preview for example doesn't)
#this script uses the apple preferences to disable it which
#works on any app. To use it simply execute the script in Terminal
#with the path the the application as the first argument
if [ -z "$1" ]
then
echo "You must specify an application"
exit 1
fi
appId=$(osascript -e "id of app \"$1\"")
currentState=$(defaults read $appId NSQuitAlwaysKeepsWindows 2>/dev/null)
if [ -z $currentState ]
then
currentState=1
fi
if [ $currentState -eq 1 ]
then
echo "Disabling saved application state for $appId"
defaults write $appId NSQuitAlwaysKeepsWindows -bool false
else
echo "Enabling saved application state for $appId"
defaults write $appId NSQuitAlwaysKeepsWindows -bool true
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment