5 Replies Latest reply: Nov 11, 2007 4:51 AM by FromOZ
flipp Level 1 Level 1 (0 points)
In Tiger I was using this AppleScript snippet to launch and hide my Address Book:

tell application "Address Book" to activate
tell application "System Events" to set visible of process "iCal" to false

Now in Leopard, my Address Book is launched but the application window stays on screen. Inserting a "delay 1" between the two lines seems to do the trick -- but is there a more elegant solution?

Flipp.

Mac OS X (10.5)
  • FromOZ Level 2 Level 2 (405 points)
    Try this... (note forum software removes the tab indenting)

    ---8<-----
    tell application "Address Book"
    activate
    close front window
    end tell
    ---8<-----

    Will launch Address Book and then close window leaving application running.
  • Camelot Level 8 Level 8 (46,120 points)
    The most obvious problem is that you're telling iCal to hide, not Address Book...?

    The second approach is to tell the application to launch, not activate

    Launching an application causes it to open in the background. Activating it specifically tells it to come frontmost.

    tell application "Address Book" to launch


    I can't confirm off-hand whether it works in this particular case (it may open its window behind the current app, which is not the same as hiding), but it might work.
  • FromOZ Level 2 Level 2 (405 points)
    Except he said
    flipp wrote:
    In Tiger I was using this AppleScript snippet to launch and hide my Address Book:
    ... my Address Book is launched but the application window stays on screen


    so I did code to hide the address book. Agreed his code said hide iCal but his request was Address Book. We better wait for him to clarify I guess. Anyway snippet I posted hides Address Book.
  • flipp Level 1 Level 1 (0 points)
    The most obvious problem is that you're telling iCal to hide, not Address Book...?


    Sorry, copy and paste error in my above post. Of course I want to open and hide Address Book.

    FromOZ’s approach works great for me. With Camelot’s approach though lanching in background, Address Book’s main window is still present.

    Thank you guys!

    Message was edited by: flipp
  • FromOZ Level 2 Level 2 (405 points)
    Happy to help. Just to check, did you mark reply as 'Solved' which provided solution?

    Cheers