Follow us on...
Follow us on Twitter Follow us on Facebook
Register
Page 1 of 2 12 LastLast
Results 1 to 8 of 9
  1. #1
    3mors's Avatar
    3mors is offline HampCake Studios
    Join Date
    Oct 2001
    Posts
    665
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Unhappy close current window via applescript

    i know that it's so simple, but i can't get to close the current frontmost window using applescript, i'd like to assign this action to a button of my mighty mouse

    who could help me?
    thanks
    3mors
    ------------------------------------------------------
    iMac G5 20"/MacBook Pro 17"/PowerBook G4
    ------------------------------------------------------

  2. #2
    Mikuro's Avatar
    Mikuro is offline Crotchety UI Nitpicker
    Join Date
    Mar 2005
    Posts
    2,832
    Thanks
    8
    Thanked 74 Times in 64 Posts
    The easiest way would be to simulate command-W. You can do this in AppleScript using System Events, like so:
    Code:
    tell application "System Events" to keystroke "w" using command down
    For this to work, you need to enable GUI scripting in AppleScript Utility ("/Applications/AppleScript/AppleScript Utility.app")
    Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.8
    MacBook Pro — 2.26GHz C2D, 8GB RAM — OS 10.6.8

    Useful programs: Privoxy, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc

  3. #3
    3mors's Avatar
    3mors is offline HampCake Studios
    Join Date
    Oct 2001
    Posts
    665
    Thanks
    0
    Thanked 2 Times in 2 Posts
    i've just tried and it doesn't work, no message error shown

    [edit]
    mmm strange, it works if i run it from script editor, but not as app standalone
    i think it's because it tries to send CMD+W keystroke to the script itself and not to the frontmost window
    3mors
    ------------------------------------------------------
    iMac G5 20"/MacBook Pro 17"/PowerBook G4
    ------------------------------------------------------

  4. #4
    Mikuro's Avatar
    Mikuro is offline Crotchety UI Nitpicker
    Join Date
    Mar 2005
    Posts
    2,832
    Thanks
    8
    Thanked 74 Times in 64 Posts
    Yeah, that would be it. Can't you have it just activate a script, rather than an applet? I'm not all that familiar with Apple's driver.

    You could use a third-party driver like USB Overdrive to simulate the keystroke itself.

    I'm not sure launching an applet would be responsive enough for such a task, but there is a way to get around the problem you have: Make your applet an "invisible" app that doesn't show up in the Dock or get focus. You can do this by saving this script as an Application Bundle (not as just "Application"), and then editing its Info.plist to include this right after the first <dict> tag:
    Code:
    	<key>LSUIElement</key>
    	<string>1</string>
    After saving the changes, move the applet to a different folder, and it should work.

    But again, I doubt it would be responsive enough.
    Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.8
    MacBook Pro — 2.26GHz C2D, 8GB RAM — OS 10.6.8

    Useful programs: Privoxy, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc

  5. #5
    3mors's Avatar
    3mors is offline HampCake Studios
    Join Date
    Oct 2001
    Posts
    665
    Thanks
    0
    Thanked 2 Times in 2 Posts
    sorry, but i can't get it to work
    3mors
    ------------------------------------------------------
    iMac G5 20"/MacBook Pro 17"/PowerBook G4
    ------------------------------------------------------

  6. #6
    Mikuro's Avatar
    Mikuro is offline Crotchety UI Nitpicker
    Join Date
    Mar 2005
    Posts
    2,832
    Thanks
    8
    Thanked 74 Times in 64 Posts
    What OS version are you running? I think it ought to work in Panther or even Jaguar, but I'm not sure I ever tested it before Tiger.

    Anyway, try the attached applet. Works for me.
    Attached Files Attached Files
    Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.8
    MacBook Pro — 2.26GHz C2D, 8GB RAM — OS 10.6.8

    Useful programs: Privoxy, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc

  7. #7
    dmetzcher's Avatar
    dmetzcher is offline Metzcher.com
    Join Date
    Apr 2005
    Location
    New Jersey, USA
    Posts
    578
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by 3mors
    i know that it's so simple, but i can't get to close the current frontmost window using applescript, i'd like to assign this action to a button of my mighty mouse

    who could help me?
    thanks
    Current frontmost window of what? Finder? Another app? Or are you looking for something non-specific?
    Dennis R. Metzcher
    Metzcher.com

  8. #8
    3mors's Avatar
    3mors is offline HampCake Studios
    Join Date
    Oct 2001
    Posts
    665
    Thanks
    0
    Thanked 2 Times in 2 Posts
    a non-specified frontmost window: i'd like to assign this script to the middle button of my mighty mouse as i've done with my logitech mouse (using the logitech driver) in order to close the frontmost window of the app i'm using

    otherwise i need to use a third-part apps such as usboverdrive, but i'd like to avoid it

    the app you posted doesn't work
    3mors
    ------------------------------------------------------
    iMac G5 20"/MacBook Pro 17"/PowerBook G4
    ------------------------------------------------------

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Does anyone else wish they could close a window with expose?
    By Fahrvergnuugen in forum Mac OS X System & Mac Software
    Replies: 20
    Last Post: December 3rd, 2009, 11:49 PM
  2. Applescript detecting file or app open/close?
    By driftwolf in forum Software Programming & Web Scripting
    Replies: 3
    Last Post: September 18th, 2005, 12:58 AM
  3. applescript to close and trash topmost document
    By tench in forum Mac OS X System & Mac Software
    Replies: 0
    Last Post: May 20th, 2004, 04:28 AM
  4. How to close the Terminal window after a while using AppleScript?
    By voice- in forum Software Programming & Web Scripting
    Replies: 3
    Last Post: December 23rd, 2003, 01:37 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
  •