Professional Web Applications Themes

Adding a Menu Item to an Apple app - Mac Programming

Hi, To satisfy a long-running itch, I've written an application which alphabetically sorts Safari bookmarks by reading and overwriting ~/Library/Safari/Bookmarks.plist. (It was pretty tricky for this amateur, calling CFTreeSortChildren recursively, but it seems to work now; I've even got a couple preference options in how they are sorted.) To finish it off, I'd like to write an "installer" which would somehow hack Safari, adding a "Sort Bookmarks Alphabetically" menu item to it, and launch my application when the user selects this menu item. I'm not sure this is even possible, but it seems to me that, if it is possible, ...

  1. #1

    Default Adding a Menu Item to an Apple app

    Hi,

    To satisfy a long-running itch, I've written an application which
    alphabetically sorts Safari bookmarks by reading and overwriting
    ~/Library/Safari/Bookmarks.plist. (It was pretty tricky for this amateur,
    calling CFTreeSortChildren recursively, but it seems to work now; I've even
    got a couple preference options in how they are sorted.)

    To finish it off, I'd like to write an "installer" which would somehow hack
    Safari, adding a "Sort Bookmarks Alphabetically" menu item to it, and
    launch my application when the user selects this menu item. I'm not sure
    this is even possible, but it seems to me that, if it is possible, there
    might be a "correct" and a "wrong" way to do it.

    So, before I start googling developer.apple.com, I thought I'd ask if anyone
    might care to please steer me in the "correct" general direction.

    Thanks!

    Jerry Krinock
    San Jose, CA USA

    Jerry Guest

  2. #2

    Default Re: Adding a Menu Item to an Apple app

    On Sun, 7 Dec 2003, Jerry Krinock wrote:
     

    If this is possible, I do not believe it to be possible in an easy and
    reliable way. One way out would be to write an applescript that runs your
    application, and put the scripts in ~/Library/Scripts, so that it appears
    in the scripts Menu extras.

    Another possible issue you may run into is that it is very likely that
    changing the Bookmarks file may not force Safari to reload its bookmarks
    straightaway.

    Fred
     

    Frederick Guest

  3. #3

    Default Re: Adding a Menu Item to an Apple app

    In article <BBF8757F.14FB1%com>,
    Jerry Krinock <com> wrote:
     

    Basically, you need to get into Safari's address space somehow. Probably
    the best-known way is with APE (http://unsanity.com/ape/). It lets you
    write a plugin that gets loaded into any app you want when the app runs;
    at that point, you can add menus, or do anything else you need. APE has
    some disadvantages. First, it's rather infamous. Many people blame APE
    plugins for all kinds of problems. Second, you have to actually have APE
    installed. And last, it's very powerful, much more than you need for
    this little project.

    A better alternative is probably to write an input manager. This is
    supposed to provide an alternate input mechanism to Cocoa apps, but you
    can do whatever you want in the code, and it gets loaded into every
    Cocoa app's memory space. I haven't actually made one of these, and it's
    a little hard to find doentation on them. This post has some info and
    pointers to examples:
    <http://cocoa.mamasam.com/COCOADEV/2003/01/2/55519.php>.

    Before you do this, though, does this actually work? Does Safari see the
    changes you've made to its bookmarks file without having to quit and
    restart it?
    Michael Guest

  4. #4

    Default Re: Adding a Menu Item to an Apple app

    In article <BBF8757F.14FB1%com>,
    Jerry Krinock <com> wrote:
     

    There is no need to hack Safari. Make your program into a service, and it will
    appear in the Services submenu of the Safari application menu. This will also
    allow you or your users to assign a keyboard shortcut to your service.

    hth

    meeroh
     

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

  5. #5

    Default Re: Adding a Menu Item to an Apple app

    in article mail-1AE68C.16084307122003localhost, Michael Ash at
    com wrote on 03/12/07 07:08:
     
    Thanks very much for your insights. I will study these.
     

    Surprisingly, yes! Even if the user "Show[ing] All Bookmarks", as soon as
    the window comes back into focus after the Bookmarks file is replaced, it
    automatically reads in the new file and refreshes the view. It acts though
    it is constantly monitoring the modification time of the Bookmarks file.

    in article mit.edu, Miro
    Jurisic at org wrote on 03/12/07 09:09: 
    I kind of wanted to have it in the Bookmarks menu, but this indeed looks
    like the __right__, low-maintenance, supported, way to do it. I shall
    study this too.

    Thanks again, folks.

    Jerry

    Jerry Guest

  6. #6

    Default Re: Adding a Menu Item to an Apple app

    In article <BBF8C62A.15237%com>,
    Jerry Krinock <com> wrote:
     
    > I kind of wanted to have it in the Bookmarks menu, but this indeed looks
    > like the __right__, low-maintenance, supported, way to do it. I shall
    > study this too.[/ref]

    I don't know why I didn't think of making it a service, but I agree with
    meeroh that this is the right way to go. It's easier to write, and has a
    much smaller chance of breaking whenever Apple updates Safari next time.
    Michael Guest

Similar Threads

  1. Add new Item on Pop Up Menu
    By Pierrick_Chantrel@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 0
    Last Post: April 2nd, 02:57 PM
  2. Adding a font Apple LiSung
    By andrea_harbour@adobeforums.com in forum Adobe Photoshop Mac CS, CS2 & CS3
    Replies: 2
    Last Post: May 11th, 07:09 PM
  3. Double Apple menu items on Projector MX playback in OS 9
    By sherwinho webforumsuser@macromedia.com in forum Macromedia Director Basics
    Replies: 0
    Last Post: August 7th, 11:10 AM
  4. Apple menu script error
    By prw webforumsuser@macromedia.com in forum Macromedia Director Basics
    Replies: 4
    Last Post: July 27th, 04:42 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