using accessibilty API to move Finder windows - works, but last position not saved.

  • Hello All!

    I've successfully using the Accessibility API to move windows around
    the screen (see http://zooom.coderage-software.com for the program),
    and I've got an issue whereby when I move the Finder window by hand,
    i.e. with the mouse, then close it and reopen it - the position and
    size is as I left it.  However, when I resize the same window via my
    program (which uses only accessibility calls, e.g. AXUIElementSetValue
    ()) - the resize operation completes OK, but when I close the window
    and reopen it, the size is as it was *before the resize operation*.

    Which is weird.  And I don't understand it!

    Is there a known way of telling windows in general to save their
    positions?

    Thanks

    John Clayton
  • on 2006-10-27 12:50 AM, John Clayton at <john_clayton...> wrote:

    > I've successfully using the Accessibility API to move windows around
    > the screen (see http://zooom.coderage-software.com for the program),
    > and I've got an issue whereby when I move the Finder window by hand,
    > i.e. with the mouse, then close it and reopen it - the position and
    > size is as I left it.  However, when I resize the same window via my
    > program (which uses only accessibility calls, e.g. AXUIElementSetValue
    > ()) - the resize operation completes OK, but when I close the window
    > and reopen it, the size is as it was *before the resize operation*.
    >
    > Which is weird.  And I don't understand it!

    What do you mean by "reopen"? The Command-N keyboard shortcut in the Finder
    is labeled "New Finder Window." When you use it, I wouldn't expect it to
    give you the "same" window.

    I've never actually parsed out what logic the Finder employs to determine
    where a new window will be located and what size it will be given. If I
    create a new window and have Finder's General Preferences set to "New Finder
    windows open" showing the contents of my Home folder, then resize that
    window, close it, and choose "New Finder Window" again, it "reopens" at the
    last size I set my Home folder window to. But if I open another folder
    within that window, then resize, close and choose "New Finder Window" again,
    it creates a new window onto my Home folder back at the size I last set my
    Home folder window to. I think that's the logic, but I haven't spent much
    time trying to verify it.

    > Is there a known way of telling windows in general to save their
    > positions?

    The accessibility API is designed to emulate as closely as possible what a
    user can do with the targeted application when using the mouse and keyboard.
    The behavior of an application's windows depends entirely on how that
    application is written. Applications that have single windows are typically
    written so that the window remembers where it was and how big it was when it
    was last closed, and the same is usually true of document-based applications
    when you "reopen" a window onto the same document. But the Finder doesn't
    follow that metaphor, presumably because you can open as many Finder windows
    as you like showing the contents of the same folder -- there isn't a simple
    one-to-one correspondence between a folder and a Finder window.

    --

    Bill Cheeseman - <wjcheeseman...>
    Quechee Software, Quechee, Vermont, USA
    http://www.quecheesoftware.com

    PreFab Software - http://www.prefab.com/scripting.html
    The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
    Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes
  • Hi Bill, thanks for your reply.

    Here's my example of re-open:
    1. open the home folder using finder (Command-UpArrow while desktop
    has focus)
    2. move it around
    3. click on the desktop and re-open that home folder again

    you'll notice that the size and position are kept for this folder.
    Interestingly, if we search the internet for finder problems related
    to spatial arrangement there's a few articles around lamenting the
    current OS X finder implementation (Daring Fireball has one).
    Anyway, that's another conversation.

    Now - when I do the example above, but I resize that window using the
    accessibility API, then the size isn't saved!  This is annoying some
    of my users, who expect that size and position to be recorded by the
    Finder, just as if they had resized the window in the normal way.

    Also - most Cocoa apps have an easy life, because the developer can
    simply type a name into the 'Auto Save Name' text field of a window
    in interface builder and viola, position saved - that's what you are
    referrring to in the last paragraph I think.  Hmmmm... that gives me
    an idea, I wonder where that stuff gets written to?  Maybe Finder is
    holding that per-path in a database somewhere?  This is the kinda
    information I'd be looking to dig into I guess, in order to solve this.

    Other issues are coming to mind, like 'what if I *do* find this, and
    Finder is modifying the information at the same time?'  But I'll
    cross that bridge when I come to it i think, presumably the Carbon
    API to work with the Finder DB's is well aware of this issue.

    Thanks for the info, take care
    John Clayton

    On 27 Oct 2006, at 12:37, Bill Cheeseman wrote:

    > on 2006-10-27 12:50 AM, John Clayton at <john_clayton...> wrote:
    >
    >> I've successfully using the Accessibility API to move windows around
    >> the screen (see http://zooom.coderage-software.com for the program),
    >> and I've got an issue whereby when I move the Finder window by hand,
    >> i.e. with the mouse, then close it and reopen it - the position and
    >> size is as I left it.  However, when I resize the same window via my
    >> program (which uses only accessibility calls, e.g.
    >> AXUIElementSetValue
    >> ()) - the resize operation completes OK, but when I close the window
    >> and reopen it, the size is as it was *before the resize operation*.
    >>
    >> Which is weird.  And I don't understand it!
    >
    > What do you mean by "reopen"? The Command-N keyboard shortcut in
    > the Finder
    > is labeled "New Finder Window." When you use it, I wouldn't expect
    > it to
    > give you the "same" window.
    >
    > I've never actually parsed out what logic the Finder employs to
    > determine
    > where a new window will be located and what size it will be given.
    > If I
    > create a new window and have Finder's General Preferences set to
    > "New Finder
    > windows open" showing the contents of my Home folder, then resize that
    > window, close it, and choose "New Finder Window" again, it
    > "reopens" at the
    > last size I set my Home folder window to. But if I open another folder
    > within that window, then resize, close and choose "New Finder
    > Window" again,
    > it creates a new window onto my Home folder back at the size I last
    > set my
    > Home folder window to. I think that's the logic, but I haven't
    > spent much
    > time trying to verify it.
    >
    >> Is there a known way of telling windows in general to save their
    >> positions?
    >
    > The accessibility API is designed to emulate as closely as possible
    > what a
    > user can do with the targeted application when using the mouse and
    > keyboard.
    > The behavior of an application's windows depends entirely on how that
    > application is written. Applications that have single windows are
    > typically
    > written so that the window remembers where it was and how big it
    > was when it
    > was last closed, and the same is usually true of document-based
    > applications
    > when you "reopen" a window onto the same document. But the Finder
    > doesn't
    > follow that metaphor, presumably because you can open as many
    > Finder windows
    > as you like showing the contents of the same folder -- there isn't
    > a simple
    > one-to-one correspondence between a folder and a Finder window.
    >
    > --
    >
    > Bill Cheeseman - <wjcheeseman...>
    > Quechee Software, Quechee, Vermont, USA
    > http://www.quecheesoftware.com
    >
    > PreFab Software - http://www.prefab.com/scripting.html
    > The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
    > Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes
    >
    >
    > _______________________________________________
    > MacOSX-dev mailing list
    > <MacOSX-dev...>
    > http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • on 2006-10-29 3:59 AM, Clayton John at <john_clayton...> wrote:

    > Now - when I do the example above, but I resize that window using the
    > accessibility API, then the size isn't saved!  This is annoying some
    > of my users, who expect that size and position to be recorded by the
    > Finder, just as if they had resized the window in the normal way.

    Yes, I see what you mean. It works that way here, too, using my UI Browser
    product. I was initially tempted to say that this is because the
    accessibility API considers a window to be "destroyed" when it is closed.
    However, despite this, a closed Finder window remembers the status of its
    toolbar (on/off) when it is "reopened," even if the toolbar button was
    "clicked" using the accessibility API (I didn't test whether this is also
    true when changing the icon view via the accessibility API).

    So, apparently, the failure to remember its size is a Finder accessibility
    bug, since manually resizing a Finder window is remembered when it is
    "reopened."

    I'm copying this message to the accessibility mailing list, because Apple
    accessibility engineers lurk there. If you have access to Apple's bug
    reporter, you should report this.

    > Also - most Cocoa apps have an easy life, because the developer can
    > simply type a name into the 'Auto Save Name' text field of a window
    > in interface builder and viola, position saved - that's what you are
    > referrring to in the last paragraph I think.  Hmmmm... that gives me
    > an idea, I wonder where that stuff gets written to?  Maybe Finder is
    > holding that per-path in a database somewhere?  This is the kinda
    > information I'd be looking to dig into I guess, in order to solve this.

    Autosave name window position, size, etc., are generally saved in the
    application's own preferences file.

    > Other issues are coming to mind, like 'what if I *do* find this, and
    > Finder is modifying the information at the same time?'  But I'll
    > cross that bridge when I come to it i think, presumably the Carbon
    > API to work with the Finder DB's is well aware of this issue.

    You'll certainly need to consider issues like this.

    --

    Bill Cheeseman - <wjcheeseman...>
    Quechee Software, Quechee, Vermont, USA
    http://www.quecheesoftware.com

    PreFab Software - http://www.prefab.com/scripting.html
    The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
    Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today