Tile Safari Windows in Current Space

Hello everyone,
I'm trying to fix this apple script to only work on the windows in the current Space.
--When in Safari, the coordinates {0,0} refer to the upper corner not including the menubar.
tell application "Safari"
-- For some reason Safari has two invisible windows
set allWindows to (every window where visible is true)
set n to (count of allWindows)
-- Determine screen size of your machine
tell application "Finder"
set screenSize to bounds of window of desktop
set screenWidth to item 3 of screenSize
set screenHeight to item 4 of screenSize
end tell
-- Dividing by zero is bad
if n is equal to 0 then return
set windowWidth to screenWidth / n
if (n > 0) then
activate
set x to 1
-- Position each window in turn
repeat
tell window x
set bounds to {windowWidth * (x - 1), 0, windowWidth * x, screenHeight}
end tell
set x to x + 1
if x is equal to (n + 1) then exit repeat
end repeat
end if
end tell
The problem is that if I have multiple safari windows open, the variable allWindows is set to the number of safari windows in every space combined. I only want to tile the windows in the current space, and if I use this script as it is now it will tile them, but it will set their widths to allow for all windows in every space to be tiled along side. This leaves more empty space depending on how many other windows I have open.
Does anyone know how to test how many windows are only in the current space?
I'm terrible with Applescript, so specifics will be very much appreciated.
Thank you.

Hello,
Thank you for your reply, Pierre.
Just in case anyone is wondering, I didn't write this script, I found it somewhere online and then promptly forgot where. However, it doesn't work very well if I have other windows in other spaces, so I wanted to see if I could figure it out.
It's still not working correctly, it seems to work the same way as before:
--When in Safari, the coordinates {0,0} refer to the upper corner not including the menubar.
set theTargetIDs to {}
tell application "Safari"
set theIDs to id of every window
set theIDs to reverse of theIDs -- to keep the initial stacking order
repeat with thisID in theIDs
set index of window id thisID to 1 -- try to change the index value
if index of window id thisID is 1 then -- the window is in the current space
copy (thisID as number) to the beginning of theTargetIDs
end if
end repeat
theTargetIDs -- from front to back - the windows that are in the current space
set n to (count of theTargetIDs)
-- Determine screen size of your machine
tell application "Finder"
set screenSize to bounds of window of desktop
set screenWidth to item 3 of screenSize
set screenHeight to item 4 of screenSize
end tell
-- Dividing by zero is bad
if n is equal to 0 then return
set windowWidth to screenWidth / n
if (n > 0) then
activate
set x to 1
-- Position each window in turn
repeat
tell window x
set bounds to {windowWidth * (x - 1), 0, windowWidth * x, screenHeight}
end tell
set x to x + 1
if x is equal to (n + 1) then exit repeat
end repeat
end if
end tell
Am I missing something? I don't think that script is selecting only the windows in the current space- it's still tiling in every space. Can you take a look?
Sorry for my incapability to help myself. :S
Thank you.

Similar Messages

  • I would like to open different Safari windows in different Spaces

    I would like to be able to open different Safari windows in different Spaces. They guy at the Apple store told me this was impossible, but I am 99% sure that I accidentally had it working this way before I realized what Spaces was, but now that I have set my Spaces preferences, I cannot get it to work for me.
    Ideally, my husband could use one space - he only uses Safari. And I could use the other Spaces for my various applications, including Safari.
    Any suggestions appreciated!

    I do it as follows.
    I don't have Safari assigned to any (or all) spaces. I don't have the little checkbox checked at the bottom of Spaces preferences ("When switching to an application...").
    In a given space I click on Safari in the dock. This makes it the active application. Of course, if a window is already open in that space it will come to the front. But suppose there isn't a window open. I then ask for a new window (via the File menu, or via command-n). Voila. That window is in that space. You can do this in any space and the windows stay where you created them.
    (A shortcut is simply to control-click on the Safari dock icon and select "New Window".)
    charlie

  • Spaces confusing safari windows (on multiple spaces using command-tab)

    Wondering if this is happening to anyone else.
    I love spaces but something is messed when using safari windows on multiple spaces. Say I have two safari windows open on two different spaces, after command-tabbing to another app when I try to command-tab back to safari it doesn't always go to my last safari window. That is to say that sometimes it goes to the other safari window, and sometimes it doesn't. It's super unpredictable.
    Give it a try, open two safari windows on two different spaces and the command tab to another app and then command tab back to safari - and repeat... you'll find that it will just randomly go to the other window, and then back etc.
    Can't think of anything more annoying in spaces... that's got to be a bug.
    Anyways, let me know if it's happening to you.
    Jay.

    same issue. i have multiple safari windows with multiple tabs on multiple spaces. let's say one space is a rails space; so it has some terminals, safaris, firefoxes, all perhaps with 2 or more tabs. command-tab does not necessarily go back to the window of the app i was just in. whether it's safari or firefox or whatever. this is horribly un-intuitive. come on apple. that's like your thing, right?

  • Shortcut to cycle open windows in current Space?

    Hi!
    How can I get a shortcut to cycle only between the windows in the current space?
    Please help!
    /roda

    "the default shortcut for this is control+F4 (or controlfnF4 depending on the keyboard you are using). You can change it to what you like in system preferences->keybaord->keyboard shortcuts->keyboard and text input."
    Thanks alot -- this does exactly what I need!
    /roda

  • Can someone tell me why Safari windows follow from space to space?

    I open a new space via Mission Control.  I want to have only a couple terminal windows in there.  For some reason Safari windows follow me when I switch from one space to another.  Why is this?  It doesn't happen with email, Firefox, or any other application.  Is there some setting that got flipped inadvertently?  I know this will sound strange but this happened today when updating to IOS 5 and my OS X Lion was updated too.
    Note that when there's at least 1 Safari window in full screen I can create another, put it in non-full screen mode and Safari windows will NOT follow spaces.

    right-click or hold-down after clicking on Safari in your dock -- look at options > Assign to
    It sounds like you have 'all desktops' selected there.
    Choose 'this desktop' or 'none'

  • Resizing Safari Window causes blank space

    When I resize a safari window using the corner (bottom right) it leave a blank space if I make he page bigger and doesnt fill the page at all unless i press refresh.

    .oO(CJR 2007)
    >I'm pretty new to website design and this might seem very
    basic, but how is it
    >possible to resize a browser window automatically to fit
    the content on my page
    >using Dreamweaver CS3?
    You should rather make the site fit the browser window.
    > The content of my page is 700px by approximately 650 but
    I want the browser
    >window to show just this content and not the blank space
    surrounding it.
    Resizing the browser window is considered _very_ rude, if it
    will work
    at all - modern browser prevent such abuse of JavaScript.
    You should more concentrate on the content and the usability
    of the site
    to attract visitors. Keeping the layout flexible is usually
    the best way
    to go. But even if it has to be a fixed-width layout, you
    shouldn't mess
    with the user's browser settings, but for example center the
    entire site
    in the browser. Solutions for that are posted here every
    second day.
    Micha

  • AppleScript: How to reload a Safari window without bring the window to the foreground while I am on other Desktop space

    I want to write an AppleScript to achive a simple task. That is, I open a Safari window on Desktop 1 and automatically reload every 30 minutes while I do my dialy work on desktop 2.
    Here is my script:
    tell application "Safari"
        activate
        tell application "System Events"
            tell process "Safari"
                keystroke "r" using {command down}
            end tell
        end tell
    end tell
    This script works. However, whenever the script is executed, my current Desktop 2 will be brought back to Desktop 1. It is distracting to my workflow.
    Is there any way to just let Safari to reload in the background without bring Safari window to foreground on Desktop 1?
    I have done a coumple of researches; many of them say I should not use "activate" in my script. I tried that but then the script will just do nothing.

    Hi, Hiroto
    your approach works perfectly fine. Thank you.
    I just found there is also a more generic approach without tweaking of javascript or any third party scripting language involed:
    #!/usr/bin/osascript
    tell application "Safari"
        set docUrl to URL of document 1
        set URL of document 1 to docUrl
    end tell
    From there, I can do a simple cron job task now.

  • Shortcut to close window in Safari but the current?

    I've been searching all over for this. I'm sure it s obvious ,but the words that I search are so common ,I get way to much info. Anyway I want to know how I can close all safari window but the currently active. Lets say there is 5 windows or tabs open but I'm only interested in the one I'm using now. I think I remember there being one ,if not I think U can make your own. Any help would be greatly appreciated.

    752/3198
    Hi Jason,
    Using the Close All Windows (⌥⌘W) shortcut does not affect minimized windows, so,
    hit first the Minimize shortcut (⌘M)
    to put your window in the Dock,
    then Close All Windows.
    The only window(s) left will be the one(s) in the Dock.
    HTH
    Axl

  • Two clicks required for Safari window which is not currently the focus

    This is really starting to annoy me - I have a 17" powerbook so I can display two webpages side by side. I click on a link in one page and... ...nothing happens. If this page was not the current focus, my first click just changes the focus - i then have to click again to go to the link. Many times i sit there waiting for the display to update, only to find that it is not going to because it requires another click... Is there any way to make Safari take action on the first click on a window not currently in focus?

    I don't know of any way to allow this.
    Mail works the same way.
    using mail & safari windows side by side does the same, as does anything(?) that involves switching applications.
    It's just the links in safari that require one click to focus then one to activate - running two safari windows & clicking something in the toolbar or bookmarks bar on the 'other' window works just fine. As does clicking a 'button' within the page (like 'post message' on these boards,for example)
    I can only suggest letting Apple know what you think at http://www.apple.com/macosx/feedback/

  • Opening apps/Safari windows-want them to open behind current window ?

    Ok, maybe small beer, but, when I open a Safari window from, for eg, google reader, the new window opens in front of my current Safari window, the window I am reading. This means that it covers my current window, which is annoying, to me. Similarly, when I open an application, the new app insists on coming to the front, and interrupting my work. As I said, small beer, but annoying.
    Is there a way to make all new Safari windows and new apps start 'behind' the currently active window/app?

    No. Why are you opening new windows when you don't want to act in them? Don't open them and you won't be disturbed.

  • White space at bottom of Safari window

    I need a little help with a very odd problem.
    When I load websites that I have created with iWeb '09 using Safari on my Mac, I sometimes get a portion of the page (always near the bottom of the page) that displays as white, and not the color of the browser background color that I have published. However, if I click anywhere on my desktop (i.e., the Finder) while the Safari window is open, then the white space is instantly changed to the correct color.
    I am running the latest versions of all Apple software, and I have run both disk repair and permissions repair on my hard drive. I have also reset the PRAM on my Mac Pro.
    This is both annoying and puzzling. Does anyone have any suggestions? I am running Snow Leopard 10.6.2 and iWeb '09.
    Thanks,
    -AstraPoint
    (note: we also posted this problem on the iWeb '09 forum pages)

    My tutorial (http://toadstutorials.info) and demo sites (Old Toad's Demo Sites) are crated with no page background and a tiled image for the browser background so haven't had the situation you've have. But some of the demo pages had a lot of stuff on it and does load slowly at times with no issue regarding background.
    Give it a try.

  • How many Safari windows can I open at one time?

    I have an old habit of keeping lots of Safari windows open at one time, instead of closing them as I go. I'm using a G4 iBook with 768 of RAM over an Airport wireless system. I have at least 40 gigs of open space on my HD and recently repaired permissions and emptied cache and history, but it takes FOREVER for new pages to load. I've enabled the interference filter, which seemed to help for a day or so, but I'm back to beach ball ****. Meanwhile, my spouse is using a TiBook 667 with Airport card on the same Airport base station, and has none of the delays I do.
    Does having a couple dozen Safari windows open at one time slow the whole program down? If not, anyone have any other ideas?

    iTunes will only open one library at a time.
    Regards.

  • How to force weblinks to open in a new Safari window

    Hi,
    This morning, I just upgraded Lion from 10.7.3 to 10.7.4, and I upgraded Safari to Version 5.1.7 (7534.57.2).  Since then, when I click on web links in messages in Mail, they seem to open in a tab in an existing Safari window, where they used to open in a new Safari window, which is what I want.  It also appears that these pages load, they are loading in an existing tab and flushing the history, so tabbed pages end up disappearing with no way to determine exactly what they once were.  My Safari tab preferences are "Open pages in tabs instead of windows:  Never", and the checkboxes below this option are both unchecked.  Any help would be much appreciated, as I usually have multiple Safari windows open, each with 2-4 tabs active, and this current behaviour is quite destructive.
    Thanks,
    Ken

    Please read this whole message before doing anything.
    This procedure is a diagnostic test. It’s unlikely to solve your problem. Don’t be disappointed when you find that nothing has changed after you complete it.
    The purpose of this exercise is to determine whether the problem is caused by third-party system modifications that load automatically at startup or login. Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot in safe mode* and log in to the account with the problem. The instructions provided by Apple are as follows:
    Be sure your Mac is shut down.
    Press the power button.
    Immediately after you hear the startup tone, hold the Shift key. The Shift key should be held as soon as possible after the startup tone, but not before the tone.
    Release the Shift key when you see the gray Apple icon and the progress indicator (looks like a spinning gear).
    *Note: If FileVault is enabled under Mac OS X 10.7 or later, you can’t boot in safe mode.
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including wireless networking on certain Macs.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Test while in safe mode. Same problem(s)?
    After testing, reboot as usual (i.e., not in safe mode) and verify that you still have the problem. Post the results of the test.

  • How to make screenshot/jpg/pdf of ENTIRE long Safari window (not just visible part)?

    I want to get a "screenshot" (i.e. an image in any format -- PNG, JPG, PDF, whatever) of a looooooooong Safari window diplaying a Web page that entends far below the bottom of the visible screen area and has to be scrolled down to see all of it.
    I know about the standard screenshot keyboard tricks in 10.6 -- Command-shift-4, Command-shift-4 then spacebar/click, Command-shift-3, etc. But not any of them allow the user to get a screen shot of the entirety of a long/deep window -- they only capture what is visible on the screen.
    Also, another trick people often mention is to "print" (command-P) the Safari page, but instead of sending it to a printer choose "Save as PDF." Brilliant -- except that for some reason I've never been able to "print" a Safari page -- as soon as I hit the command-P keystrokes in Safari, I immediately get a spinning beachball that will only go a way with a force-quit of Safari. This has always been true on this computer (MacBook Pro) -- not sure if it's a common bug or if it's just an eccentricity of my particular machine. Either way, that option is off the table because "printing" is impossible with my Safari.
    I also searched around for various third-party freeware applications, and despite a lot of grandiose promises, none of them actually was able to capture an entire window including portions not currently visible on the screen.
    I did find a commercial application called SnapWeb that does have the capability to do exactly what I want -- but it doesn't produce usable images in demo mode and requires $$$ to unlock and work properly, something I'm currently unwilling to pay for a simple one-use gimmick that simply must be part of the OS already.
    So my question is:
    Is there any native way within the 10.6 OS that allows users to capture an entire long Safari window as an image file (not as a Web Archive, but as an image file composed of pixels), which includes the entirety of a Web page no matter how "long" it is, even if it extends far below the visible screen footprint?
    And if there is no native way in 10.6, if there a freeware/shareware application/widget/plugin/whatever which does the same thing?
    I already know about a commercial software that does it (SnapWeb), so I don't need more recommendations for paid apps. And I know that I can laboriously construct a JPEG by hand with Photoshop by taking a screenshot of the visible window, scrolling down a little, taking another screenshot, etc. etc., and then
    "stitching" them together. Yeah, it's possible (and in fact is what I've done in the past), but it's a time-consuming hassle that shouldn't be necessary.
    Help! I've wondered about how to do this for years, and have never yet found a satisfactory answer.

    Woo-hoo!
    After fiddling with Paparazzi! for another 40 minutes, I finally deciphered (through trial-and-error) how to maneuver through its awkward user-interface to an extent that I was finally able to make it "work" -- at least work sufficiently for my purposes. And lo and behold, it does indeed have the capacity to capture a screenshot of an entire long Web page, including the portion not visible on the screen. In fact my first attempt was to experiment with this very page of our thread on Apple "Discussions" about how to solve this problem -- and I got Paparazzi! to save it as a jpeg!! The whole thread, top to bottom, exactly as on the screen, not re-formatted for printing. The final file size was 985 pixels wide by 4,204 pixels long (1.2mb).
    I have since experimented with a couple other pages and had success with them as well.
    HOWEVER, I can't guarantee that Paparazzi! will work with every page on the Web, because I think one of the problems when I first attempted to use it was that the page I was trying to get a screenshot of contained a lot of Flash elements and other data-heavy widgets, and I think those messed up Paparazzi!'s memory or overwhelmed it or something. But perhaps such huge and problematic pages are rare enough to not be much of an issue using Paparazzi! under normal circumstances.
    So, I'll consider this problem "solved," and give user "jsd2" a "This helped me" star, since even though I already had Paparazzi! he encouraged me to revisit it.
    And for the record to help those who might stumble on this thread in the future seeking a solution to the same problem:
    The freeware program to get is called "Paparazzi!" and is available directly on the developers site here:
    http://derailer.org/paparazzi/
    Also, note that the current version only works with 10.6.8 or later, but if you have a previous version of the Mac OS, the developer helpfully maintains an archive of older releases that work with older OS versions -- you can access the old (and new) versions here:
    http://derailer.org/paparazzi/downloads
    It's also available for free download on various popular third-party sites, like:
    http://www.macupdate.com/app/mac/15966/paparazzi!
    Be warned that Paparazzi! does not have a very intuitive user interface, nor a user manual, so be patient with it and you should be able to figure out how to make it work.
    If you want another application that also does the trick and which has a simpler and better user experience, but you don't mind paying money to buy it, you can purchase and download "SnapWeb" on its developer's site here:
    http://www.tribalmedia.com/bts/snapweb/snapweb.html
    And if anybody seeing this in the future knows whether or not there is a native way to capture entire Web pages built in to 10.6, please post the info here. Thanks!

  • TS3274 My original iPad takes about 5 long seconds before responding to my finger tap in the safari window. Like I tap in Safari window, then count 5 seconds before I can begin typing my search words. Is this normal? I really don't remember it taking so l

    My original iPad takes about 5 long seconds before responding to my finger tap in the safari window. Like I tap in Safari window, then count 5 seconds before I can begin typing my search words. Is this normal? I really don't remember it taking so long when I bought it, but it has been this way for awhile. I have closed all open apps many times to no avail. I just reset all settings and still 5 seconds. I don't have a lot on my iPad with plenty of free space available. Also, I have to click twice on many things that typically take one click. Like it highlights it with first click, then second click completes the action that normally would be done in one click, like Facebook like button. Like will underline with click one, then will change to like on second click. Do I need to try to restore from my computer?
    Thanks for any help!

    Ive tried that but when Im logged in I dont have all the permmisions I should have so it just runs the test for my usernames own little virtual world.  Ive been using macs for over a decade now and I have never had my computer do anything like this. while sitting in front of my screen I watched the mouse go to some personal files and change the permissions and then covered their tracks by changing the timestamp on the file dates back. I watched it happpen while all internet conections were off.  I had my identity stolen, my facebook password changed, my email accounts closed out. and my firmware password changed all within two weeks of the origninal boot date

Maybe you are looking for