Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Saturday, May 14, 2016

How can one invoke a keyboard shortcut from within an AppleScript?

How can one invoke a keyboard shortcut from within an AppleScript?


I need to invoke a keyboard shortcut from within an AppleScript code, e.g. Cmd+Ctrl+Opt+E.

Answer by regulus6633 for How can one invoke a keyboard shortcut from within an AppleScript?


Sure it works. System events can perform keystrokes. However, keystrokes are always sent to the frontmost application so to perform a shortcut for an application you must tell that app to activate first and then perform the shortcut. For example, I can open a new tab in Safari using command-t. That applescript would look like this...

tell application "Safari" to activate  tell application "System Events"      keystroke "t" using command down  end tell  

Now suppose you have a global keyboard shortcut. Global meaning it works from any application. Then you don't even need to activate an application first, just perform the keystroke. To press the keys you requested do this...

tell application "System Events"      keystroke "e" using {command down, option down, control down}  end tell  

Answer by Zygmunt for How can one invoke a keyboard shortcut from within an AppleScript?


activate application "Safari"

is 7 characters shorter than

tell application "Safari" to activate

;)

Answer by Alex Zavatone for How can one invoke a keyboard shortcut from within an AppleScript?


You can invoke the keystroke, or if GUI Scripting is on, you can select a menu item from a menu.

Here's a great link explaining this in detail.

http://hints.macworld.com/article.php?story=20060921045743404

Answer by Kristian for How can one invoke a keyboard shortcut from within an AppleScript?


activate application "Safari"    delay 3  tell application "System Events"      keystroke "t" using {command down}      delay 2      keystroke "www.google.com"      key code 36  end tell  

Answer by Michael Sanders for How can one invoke a keyboard shortcut from within an AppleScript?


depending on what you wish the keyboard shortcut to be you would use key stroke events for example

tell application "System Events" keystroke "e" using {command down, option down, control down} end tell

replace the "e" from after key stroke with what word or words you wish to input and then change the {command down, option down, control down} to which keys you wish to be activated at the same time.

thankyou


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.