Tuesday, September 2, 2014

#1 2008-04-02 05:58:12 am

ntnwwnet
Member
Registered: 2007-02-10
Posts: 11

"Eject" Keystroke?

I'm trying to write a script that simulates the keystroke combination "Shift" + "Control" + "Eject".

I can't try to figure out how to pass the keystroke for "Eject".

So far, I have this:

Applescript:


tell application "System Events"
   keystroke ?EJECT? using control down & shift down
end tell


Filed under: System

Offline

 

#2 2008-04-02 12:26:36 pm

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10490
Website

Re: "Eject" Keystroke?

Hi,

there is no key code for the eject key, therefore it is not accessible with AppleScript


regards

Stefan

Offline

 

#3 2008-04-02 12:39:05 pm

mark hunte
Member
From: Hello, London Calling
Registered: 2006-03-20
Posts: 1019
Website

Re: "Eject" Keystroke?

Applescript:

do shell script "drutil eject -drive internal"

for internal

or plain

Applescript:

shell script "drutil eject "

or "One of the following keywords: internal, external, usb,
                  firewire, atapi, scsi."


Tap,tap,tap , hello , testing 1..2,  1...2,
http://www.markosx.com/thecocoaquest/

Offline

 

#4 2008-04-02 12:42:28 pm

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10490
Website

Re: "Eject" Keystroke?

mark hunte wrote:

Applescript:

do shell script "drutil eject -drive internal"

for internal

And how do you handle the modifier keys? wink


regards

Stefan

Offline

 

#5 2008-04-02 12:47:13 pm

mark hunte
Member
From: Hello, London Calling
Registered: 2006-03-20
Posts: 1019
Website

Re: "Eject" Keystroke?

StefanK wrote:

mark hunte wrote:

Applescript:

do shell script "drutil eject -drive internal"

for internal

And how do you handle the modifier keys? wink

Doh.
Good point.roll

What are they for anyway?

** Ah tell the display to sleep

Last edited by mark hunte (2008-04-02 01:04:18 pm)


Tap,tap,tap , hello , testing 1..2,  1...2,
http://www.markosx.com/thecocoaquest/

Offline

 

#6 2008-04-03 08:25:49 am

Matt-Boy
Member
Registered: 2005-10-21
Posts: 480

Re: "Eject" Keystroke?

That key combo doesn't do anything on my computer, but assuming the intention is to put the computer to sleep...

Applescript:

tell application "Finder" to sleep


Filed under: Finder

Offline

 

#7 2008-04-03 09:14:00 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10490
Website

Re: "Eject" Keystroke?

Matt-Boy wrote:

That key combo doesn't do anything on my computer, but assuming the intention is to put the computer to sleep...

Applescript:

tell application "Finder" to sleep

subtle but important difference:
⌃⇧⏏ puts the display to sleep
⌥⌘⏏ (the same as your script) puts the computer to sleep


regards

Stefan

Filed under: Finder

Offline

 

#8 2008-04-03 10:29:15 am

Matt-Boy
Member
Registered: 2005-10-21
Posts: 480

Re: "Eject" Keystroke?

Ah, I get it.

You can't reference the eject key, and there is no syntax to directly sleep the display. Who knew this would be so difficult...

The only solutions I found searching involve shell scripts that temporarily set the display sleep to the shortest setting and then wait that amount of time and set the settings back to what you had. Seems a little clunky to me.

Offline

 

#9 2008-04-03 01:54:19 pm

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4632

Re: "Eject" Keystroke?

It is clunky, Matt. The shortest pmset for display sleep is 1, which means one minute. Setting it to zero means "never".


iMac & MBP both running OS X 10.9.1

Offline

 

#10 2010-01-09 11:27:22 pm

thom
Member
Registered: 2006-05-08
Posts: 5

Re: "Eject" Keystroke?

Well, at least I'm not the only one who's tried to do this.

Has anyone ever found a programmatic way to sleep the display which doesn't involve waiting for one minute to have pmset do its thing?

I found mentions of a hack that only worked pre-Leopard which used a 'magic number' to fake pmset into instantly sleeping the display. But that doesn't work.

I have a handy script to do the opposite (fake pressing the shift key to wake up the display):

#!/bin/sh
/usr/bin/osascript -e 'tell application "System Events"' -e 'key down shift' -e 'delay 0.2' -e 'key up shift' -e 'end tell'

This widget works, but I don't know how to programatically invoke it:
http://www.chriskarcher.net/software/displaysleeper

There's something mentioned at the bottom of the comments on that page by yet another person ("Julia Truchsess") who wants this functionality:

http://www.dynamicallyloaded.com/produc … index.html

Sadly, the page is 404'd. But I'll probably write to them and ask about it.

Offline

 

#11 2010-01-10 01:21:27 am

thom
Member
Registered: 2006-05-08
Posts: 5

Re: "Eject" Keystroke?

Follow-up: Chris Karcher kindly sent me a command-line executable that works great.

It uses the method call documented here:

http://www.cocoabuilder.com/archive/coc … splay.html

Offline

 

#12 2010-01-10 08:17:18 am

maelcum
Member
From: Earth
Registered: 2009-11-26
Posts: 16

Re: "Eject" Keystroke?

thom wrote:

Follow-up: Chris Karcher kindly sent me a command-line executable that works great.

Would it be possible to share this with us? I'd be interested in this as well. big_smile

Update: A 29k universal (!) binary (13k if you slim it down) is available from here: http://nickmomrik.com/2007/12/17/lock-s … icksilver/

It's possible to use it from AS as well as call the binary in bash/Terminal (SleepDisplay.app/Contents/MacOS/sleepdisplay)

Works on 10.5.x as well as 10.6.x.

Last edited by maelcum (2010-01-10 09:13:54 am)


Filed under: turn off screen

Offline

 

#13 2010-01-10 09:18:39 am

maelcum
Member
From: Earth
Registered: 2009-11-26
Posts: 16

Re: "Eject" Keystroke?

btw: Is turning off the display the same as setting the brightness to 0?

If yes, then this universal binary http://mattdanger.net/2008/12/adjust-ma … -terminal/ has worked for me under 10.5.x as well as 10.6.x.
Depending on the path where you'd locate the binary, it could be as easy as:

Applescript:

do shell script "/usr/local/bin/brightness 0"


Filed under: screen brightness

Offline

 

#14 2010-12-15 09:14:30 am

Skillet
Member
Registered: 2010-01-11
Posts: 115

Re: "Eject" Keystroke?

Another possible solution might be to use dockables http://getdockables.com and launching the sleep display app.

btw: Is turning off the display the same as setting the brightness to 0?

I don't think so because even manually changing my brightness on my Cinema Displays doesn't turn them the back lighting completely off like it does on a MacBook.  Also the display brightness doesn't work on my Mac Mini at home that has generic DVI monitors plugged into it but display sleeping stops the video from outputting (i.e. control+shift+eject).

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.035 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)