Professional Web Applications Themes

AppleScript/AppleEvents positioning windows - Mac Programming

I'm trying to figure out how (if) my application can re-position windows owned by other apps. I found a simple AppleScript example: tell application "iCal" set bounds of window "iCal" to {0,0,200,300} end tell This worked fine, so I tried some simple substitution, e.g.,: tell application "TextEdit" set bounds of window "test_file" to {0,0,200,300} end tell "test_file" is window title (filename) of a text file I have open in TextEdit. I get back "TextEdit got an error: NSReceiverEvaluationScriptError: 4" Is it just the case that "TextEdit" doesn't support "set bounds" AppleEvent, or do I need to identify the window some ...

  1. #1

    Default AppleScript/AppleEvents positioning windows

    I'm trying to figure out how (if) my application can re-position
    windows owned by other apps. I found a simple AppleScript example:

    tell application "iCal"
    set bounds of window "iCal" to {0,0,200,300}
    end tell

    This worked fine, so I tried some simple substitution, e.g.,:

    tell application "TextEdit"
    set bounds of window "test_file" to {0,0,200,300}
    end tell

    "test_file" is window title (filename) of a text file I have open in
    TextEdit.
    I get back "TextEdit got an error: NSReceiverEvaluationScriptError:
    4"

    Is it just the case that "TextEdit" doesn't support "set bounds"
    AppleEvent, or do I need to identify the window some other way?
    Ultimately, I need to do this from C code, but figured if I could get
    the AppleScript working, I could figure out how to send AppleEvent
    from C.

    Background here is that my app triggers the Finder to open foreign
    doents it receives from the network, and I'd like control over
    where the display window is positioned. Ideal would be if I could get
    the foreign app to run inside a window owned by my app, but I suspect
    this is not possible. Main interest is in displaying standard text
    and graphic files; I wonder would there be a way to embed Safari
    capabilities within my app and use it as the renderer?
    Tim Guest

  2. #2

    Default Re: AppleScript/AppleEvents positioning windows

    In article <google.com>,
    net (Tim) wrote:
     

    TextEdit is buggy. Its window names are not what is showing. To get what
    TextEdit thinks the name is, do:

    tell application "TextEdit"
    name of window 1
    end tell

    I got something like "testFile /Users/reinder/Desktop"
     

    "set bounds of window 1" works fine on my system (10.3.4)
     

    Forget about those AppleScript hacks; surf to
    <http://developer.apple.com/doentation/Cocoa/Conceptual/DisplayWebCont
    ent/>

    Reinder
    Reinder Guest

  3. #3

    Default Re: AppleScript/AppleEvents positioning windows

    In article <google.com>, Tim
    <net> wrote:
     


    Your script is fine. The problem is Text Edit assigns the name
    property of a window to the doent name followed by " - " and
    followed by the full path of the doent. You can see that for
    yourself by running this script:

    tell application "TextEdit"
    set windowList to every window
    repeat with thisWindow in windowList
    display dialog (name of thisWindow as string)
    end repeat
    end tell

    There may be a better answer out there, but this script will do what
    you intended:

    tell application "TextEdit"
    set windowList to every window
    repeat with thisWindow in windowList
    if name of thisWindow begins with "test_file" then set bounds of
    thisWindow to {0, 0, 200, 300}
    end repeat
    end tell
    Chris Guest

  4. #4

    Default Re: AppleScript/AppleEvents positioning windows

    In article <google.com>, Tim
    <net> wrote:
     

    Get MoreAppleEvents:

    http://developer.apple.com/samplecode/MoreAppleEvents/MoreAppleEvents.ht
    ml
    Chris Guest

  5. #5

    Default Re: AppleScript/AppleEvents positioning windows

    Thanks!! This will always be applied to a doent that was just
    opened, so I guess "window 1" should do the job. I got the
    MoreAppleEvents stuff; now just need to figure out the syntax of the
    command string to build the event.

    I'd also love to get the www kit working, but my app is a Carbon App,
    in C, and I'm guessing maybe a bit tricky to use the Cocoa API's
    (especially, for an old-fashioned C programmer like me).
    Tim Guest

Similar Threads

  1. paramters and AppleEvents
    By Toot in forum Mac Programming
    Replies: 4
    Last Post: January 12th, 04:10 PM
  2. AppleMail and AppleEvents
    By V.Vill in forum Mac Programming
    Replies: 6
    Last Post: December 18th, 08:06 PM
  3. Replies: 4
    Last Post: November 19th, 12:20 AM
  4. Can AppleScript tell which windows are in the dock?
    By Simon Slavin in forum Mac Programming
    Replies: 0
    Last Post: August 1st, 11:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139