Created
October 5, 2011 20:28
-
-
Save rwky/1265596 to your computer and use it in GitHub Desktop.
Enables/disables application saved states on OSX Lion the right way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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