image
image

|


Go Back   macosx.com > Mac Help Forums > Mac OS X System & Mac Software

Reply
 
Thread Tools
  #1  
Old May 19th, 2006, 04:29 AM
3mors's Avatar
HampCake Studios
 
Join Date: Oct 2001
Posts: 660
Thanks: 0
Thanked 0 Times in 0 Posts
3mors is on a distinguished road
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
------------------------------------------------------
Reply With Quote
  #2  
Old May 19th, 2006, 06:38 AM
Mikuro's Avatar
Crotchety UI Nitpicker
 
Join Date: Mar 2005
Posts: 2,449
Thanks: 2
Thanked 5 Times in 5 Posts
Mikuro is on a distinguished road
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.2

I'm now a four-browser man. How on earth did this happen?!

Useful programs: PithHelmet, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc
Reply With Quote
  #3  
Old May 19th, 2006, 06:45 AM
3mors's Avatar
HampCake Studios
 
Join Date: Oct 2001
Posts: 660
Thanks: 0
Thanked 0 Times in 0 Posts
3mors is on a distinguished road
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
------------------------------------------------------
Reply With Quote
  #4  
Old May 19th, 2006, 07:12 AM
Mikuro's Avatar
Crotchety UI Nitpicker
 
Join Date: Mar 2005
Posts: 2,449
Thanks: 2
Thanked 5 Times in 5 Posts
Mikuro is on a distinguished road
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.2

I'm now a four-browser man. How on earth did this happen?!

Useful programs: PithHelmet, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc
Reply With Quote
  #5  
Old May 20th, 2006, 03:13 PM
3mors's Avatar
HampCake Studios
 
Join Date: Oct 2001
Posts: 660
Thanks: 0
Thanked 0 Times in 0 Posts
3mors is on a distinguished road
sorry, but i can't get it to work
__________________
3mors
------------------------------------------------------
iMac G5 20"/MacBook Pro 17"/PowerBook G4
------------------------------------------------------
Reply With Quote
  #6  
Old May 20th, 2006, 03:24 PM
Mikuro's Avatar
Crotchety UI Nitpicker
 
Join Date: Mar 2005
Posts: 2,449
Thanks: 2
Thanked 5 Times in 5 Posts
Mikuro is on a distinguished road
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
File Type: zip Close window.app.zip (22.0 KB, 4 views)
__________________
Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.2

I'm now a four-browser man. How on earth did this happen?!

Useful programs: PithHelmet, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc
Reply With Quote
  #7  
Old May 20th, 2006, 05:55 PM
MyMacBlog.com
 
Join Date: Apr 2005
Location: New Jersey, USA
Posts: 538
Thanks: 0
Thanked 0 Times in 0 Posts
dmetzcher is on a distinguished road
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
MyMacBlog.com: My experiences with the Mac OS, a switcher's point of view. With a new Mac tip each week day.
Reply With Quote
  #8  
Old May 30th, 2006, 03:19 PM
3mors's Avatar
HampCake Studios
 
Join Date: Oct 2001
Posts: 660
Thanks: 0
Thanked 0 Times in 0 Posts
3mors is on a distinguished road
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
------------------------------------------------------
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Applescript detecting file or app open/close? driftwolf Software Programming & Web Scripting 3 September 18th, 2005 12:58 AM
applescript to close and trash topmost document tench Mac OS X System & Mac Software 0 May 20th, 2004 04:28 AM
How to close the Terminal window after a while using AppleScript? voice- Software Programming & Web Scripting 3 December 23rd, 2003 01:37 PM
Does anyone else wish they could close a window with expose? Fahrvergnuugen Mac OS X System & Mac Software 17 July 27th, 2003 06:54 PM


All times are GMT -5. The time now is 04:06 AM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.