Created
November 21, 2011 10:41
-
-
Save midore/1382281 to your computer and use it in GitHub Desktop.
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
# shutdown.scpt | |
# | |
# Mac OS X Lion 10.7.2 | |
# AppleScript's version | |
# => "2.2.1" | |
# application "Finder"'s version | |
# => "10.7.1" | |
## https://gist.github.com/1382281 | |
script LionQuit | |
on ann(str) | |
set volume 1 | |
say str | |
set volume 0 | |
end ann | |
on msg(str) | |
ann(str) | |
tell application "Finder" to display dialog str with title "myquit" buttons {"No", "Yes", "Cancel"} default button 1 | |
return text of button returned of result | |
end msg | |
on apps_quit(i) | |
tell application i to quit | |
end apps_quit | |
on apps_close() | |
set {act_apps, apps} to get_apps() | |
repeat with i in act_apps | |
if i & ".app" is in (apps) then my apps_quit(i) | |
end repeat | |
end apps_close | |
on get_apps() | |
tell application "System Events" | |
set a to name of application processes | |
set b to (name of items of applications folder) & name of items of (folder "Applications" of (path to home folder)) | |
return {a, b} | |
end tell | |
end get_apps | |
on clean() | |
do shell script "rm -rf ~/Library/Containers/com.apple*" | |
do shell script "rm -rf ~/Library/Saved\\ Application\\ State/com*" | |
do shell script "rm -rf ~/Library/Caches/Metadata/" | |
end clean | |
on sysdown() | |
tell application "Finder" | |
close every window | |
shut down | |
end tell | |
end sysdown | |
on base(str) | |
if msg("Shut down now, OK?") is "NO" then return false | |
apps_close() | |
clean() | |
sysdown() | |
end base | |
end script | |
script Defaults_w_QAlKW | |
# defaults write NSQuitAlwaysKeepsWindows | |
on write_script(opt) | |
do shell script "defaults write com.apple.applescript NSQuitAlwaysKeepsWindows -bool" & space & opt | |
do shell script "defaults write com.apple.ScriptEditor2 NSQuitAlwaysKeepsWindows -bool" & space & opt | |
end write_script | |
end script | |
on run | |
#try | |
write_script("false") of Defaults_w_QAlKW | |
# ------------------- | |
set str to "Shut down now, OK?" | |
base(str) of LionQuit | |
#end try | |
end run | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment