• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Safari Tab Pick-List
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Safari Tab Pick-List


  • Subject: Re: Safari Tab Pick-List
  • From: Christopher Stone <email@hidden>
  • Date: Wed, 25 Apr 2012 18:56:09 -0500

On Apr 25, 2012, at 13:04, Alex Zavatone wrote:
What would rock, (I'll do it if I have time - ya, time, what is that) would be to have a way to close a Safari window when selecting it.
______________________________________________________________________

Hey Alex,

Alright.  This should be pretty bomb-proof but is not thoroughly tested.

------------------------------------------------------------------------------------------------
#       Author: Christopher Stone
#      Contact: <email@hidden>
#      Created: 2012-04-25 : 13:30
#     Modified: 2012-04-25 : 14:26 
#  Application: Safari
#      Purpose: Close selected window(s)
# Dependencies: none
------------------------------------------------------------------------------------------------
try

  

  tell application "Safari"
    activate
    set {docCount, docNames, tabCount, winIndex} to ¬
      {count, name, count of tabs, index} of (every window where its document is not missing value)
    if docCount < 10 then set docCount to "0" & docCount
    set currentTabName to (name of current tab of front window)
    set hdrText to {¬
      "-----------------------------------", ¬
      "Window Count: " & docCount, ¬
      "      Tab Count: " & tabCount, ¬
      "-----------------------------------", ¬
      "Select a window to close with ALL its tabs:", ¬
      "-----------------------------------"}
    set AppleScript's text item delimiters to return
    set hdrText to hdrText as string

    

    repeat with i from 1 to length of winIndex
      set theIndex to item i of winIndex
      set tabCnt to count of tabs of window theIndex
      set _temp to "  { Win " & theIndex & " » " & tabCnt & " Tabs }"
      set _winRef to (a reference to item i of docNames)
      tell _winRef
        set its contents to (its contents) & _temp
      end tell
    end repeat

    

    set selectedWindows to choose from list docNames ¬
      with title "•• Safari Windows ••" with prompt hdrText ¬
      default items {currentTabName} ¬
      with empty selection allowed and multiple selections allowed

    

    if selectedWindows = false then
      return
    else
      set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, linefeed}
      set selectedWindows to quoted form of (selectedWindows as text)
      set AppleScript's text item delimiters to return
      set winIndexesToClose to paragraphs of (do shell script "sed -E 's/^.+{ Win ([0-9]+).+/\\1/' <<< " & selectedWindows)

      

      # Prevent shifting window indecies.
      repeat with i in winIndexesToClose
        set contents of i to window (i as integer)
      end repeat
      repeat with i in winIndexesToClose
        close i
      end repeat

      

      set AppleScript's text item delimiters to oldTIDS
    end if
  end tell

  

on error eMsg number eNum
  set {c, s} to {return, "------------------------------------------"}
  set e to s & c & "Error: " & eMsg & c & s & c & "Error Number: " & eNum & c & s
  beep
  display dialog e
end try
------------------------------------------------------------------------------------------------

On Apr 25, 2012, at 13:04, Alex Zavatone wrote:
BUT there also is another culprit.

Your Dashboard - Weather web apps in particular.

I have Dashboard disabled.  There are some nice widgets for it, but it's a resource hog.

So, recently, I've also started to use this terminal command: purge ram

Hmm.  Where'd you get 'purge <ram>'?

As far as I know 'purge' doesn't have any parameters, but please do enlighten me if I'm mistaken.

I've also resorted to pausing Safari at times and explicitly resuming it ala the Terminal and that works like a CHARM.
To pause:
Get Safari's PID#
Issue a kill to it with a SIGSTOP
To resume:
Issue a kill to it with a SIGCONT

I haven't tried out those signals, but I'd think they would work alright in 'killall' - which allows you to use the process name instead of the pid.

Yeah; these both work:

 killall -SIGSTOP Safari
 killall -SIGCONT Safari

One script that you can help on is a one that automatically pauses Safari (as above) when it moves to the background and resumes it when it moves to the front.

Take a peek at AppTamer.

I'll play with the suspend/continue signals and see what they do for me.

I have a script that saves all Safari urls to a dated file and then kills the Web Process.  Safari will only reload the current tab in each window, but the others can be reloaded at any time.  That can free up a lot of memory if you don't want to actually dump your page-set.

I need to rewrite the save handler to create an html page with sorted links in it.

--
Best Regards,
Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Am I missing something here? I thought there was an elegant way to do this.
      • From: Alex Zavatone <email@hidden>
    • Re: Safari Tab Pick-List
      • From: Alex Zavatone <email@hidden>
    • Re: Safari Tab Pick-List
      • From: Alex Zavatone <email@hidden>
References: 
 >Safari Tab Pick-List (From: Christopher Stone <email@hidden>)
 >Re: Safari Tab Pick-List (From: Alex Zavatone <email@hidden>)
 >Re: Safari Tab Pick-List (From: Christopher Stone <email@hidden>)
 >Re: Safari Tab Pick-List (From: Alex Zavatone <email@hidden>)

  • Prev by Date: Re: Unknown token in do shell script
  • Next by Date: Re: Safari Tab Pick-List
  • Previous by thread: Re: Safari Tab Pick-List
  • Next by thread: Re: Safari Tab Pick-List
  • Index(es):
    • Date
    • Thread