Well, I decided to make this little script for Safari. Just for the lazy people. I posted this in another thread, but decided to make a thread as well.
All this does is close Safari and reopen it with the pages you had from before. Plus a handy, if poorly implemented little message at the end of it all. This isn't the most elegant way to do it, but it's the best I can do with my knowledge of AS and google
You'll need to open "Script Editor" (spotlight it), copy and paste the code below, and then press run. You can save it as a standalone app from within Script Editor if you like.
Modify, share, enjoy.
All this does is close Safari and reopen it with the pages you had from before. Plus a handy, if poorly implemented little message at the end of it all. This isn't the most elegant way to do it, but it's the best I can do with my knowledge of AS and google
Modify, share, enjoy.
Code:
-- will only work with "Safari" and "Webkit"
set brwsr to "Safari"
set before_mem to -1
if my isRunning(brwsr) then
set before_mem to my getProcMB(brwsr)
end if
tell application "System Events" to set open_apps to (get name of every application process)
if open_apps contains brwsr then
tell application brwsr to activate
tell application brwsr to quit
end if
tell application "System Events" to set open_apps to (get name of every application process)
set counter to 1
repeat while open_apps contains brwsr
delay 0.3
tell application "System Events" to set open_apps to (get name of every application process)
set counter to (counter + 1)
if (counter) is greater than 30 then
display dialog "Safari is taking too long to close, script will end now"
break
end if
end repeat
tell application "System Events" to set open_apps to (get name of every application process)
tell application brwsr to activate
tell application brwsr to activate
tell application "System Events"
tell process brwsr
tell menu bar 1
tell menu bar item "File"
tell menu "File"
click menu item "Close Window"
end tell
end tell
delay 0.1
tell menu bar item "History"
tell menu "History"
click menu item "Reopen All Windows from Last Session"
end tell
end tell
end tell
end tell
end tell
--
-- below is adapted from code by "NovaScotian" from http://forums.macosxhints.com/archive/index.php/t-64782.html
--
if my isRunning(brwsr) then
set after_mem to my getProcMB(brwsr)
end if
if before_mem is not equal to -1 then
tell application "Safari" to display dialog "You just freed up " & (before_mem - after_mem) & "MB of RAM. Nice work! :D"
end if
on isRunning(appName)
tell application "System Events" to if exists process appName then return true
return false
end isRunning
to getProcMB(procName) -- as string
try
return ((last word of (do shell script "/bin/ps -xc -o command,rss | grep " & procName)) as integer) / 1024 -- result of a division will be real
end try
end getProcMB