Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Emulating pressing F6 & F7 together with Applescript

I've been trying to create an Applescript for toggle to the Smart Tool in Pro Tools 10 & 11. The key command within Pro Tools is pressing F6&F7 together. All I can get to happen is two separate presses which just toggle other tools within Pro Tools. My closest attempt is:


tell application "Pro Tools" to activate


tell application "System Events"

key down (key code 97)

key code 98

end tell


I've tried other variations without success. Any help would be greatly appreciated.

Mac mini (Late 2012), OS X Mountain Lion (10.8.3)

Posted on Aug 1, 2013 10:20 AM

Reply
9 replies

Aug 1, 2013 1:51 PM in response to soundart11

Hello


You may try the script below.

I have tested RubyCocoa code but not the whole script, for I don't have Pro Tools or any application which accepts two F keys simultaneously.


Good luck,

H


tell application "Pro Tools" to activate

do shell script "/usr/bin/ruby <<'EOF'
require 'osx/cocoa'
include OSX

k1d = CGEventCreateKeyboardEvent(nil, 0x0061, true)     # F6 keydown
k1u = CGEventCreateKeyboardEvent(nil, 0x0061, false)    # F6 keyup
k2d = CGEventCreateKeyboardEvent(nil, 0x0062, true)     # F7 keydown
k2u = CGEventCreateKeyboardEvent(nil, 0x0062, false)    # F7 keyup

tap = KCGHIDEventTap
CGEventPost(tap, k1d)
CGEventPost(tap, k2d)
CGEventPost(tap, k1u)
CGEventPost(tap, k2u)
EOF"

Aug 1, 2013 5:54 PM in response to soundart11

Then try inserting small delay in key down and key up events. Like this -


tell application "Pro Tools" to activate

do shell script "/usr/bin/ruby <<'EOF'
require 'osx/cocoa'
include OSX

k1d = CGEventCreateKeyboardEvent(nil, 0x0061, true)     # F6 keydown
k1u = CGEventCreateKeyboardEvent(nil, 0x0061, false)    # F6 keyup
k2d = CGEventCreateKeyboardEvent(nil, 0x0062, true)     # F7 keydown
k2u = CGEventCreateKeyboardEvent(nil, 0x0062, false)    # F7 keyup

tap = KCGHIDEventTap
CGEventPost(tap, k1d)
CGEventPost(tap, k2d)
sleep 0.2
CGEventPost(tap, k1u)
CGEventPost(tap, k2u)
EOF"

Aug 2, 2013 9:11 AM in response to soundart11

Hmm. You mean it acts as if F6 was pressed and released and then F7 was pressed and released even though evens are posted differently? Then I'd guess Pro Tools is doing something special when interpretting events sequence. I give up pursuing this route.


There's good news, though. According to some resources, there're other keyboard shortcuts for Smart Tool which are F7+F8 and command+7. So you may simply use System Events' key code command for command+7 as listetd below. The key code for 7 (on keyboard not on keypad) is 0x1A (26) on English keyboard. It may vary on different keyboard hardware layout for other languages.


cf.

http://www.protoolskeyboardshortcuts.com/pro-tools-10-keyboard-shortcuts/

http://www.protoolskeyboardshortcuts.com/pro-tools-11-keyboard-shortcuts/


(*
    Smart Tool shortcuts = F6+F7, F7+F8 or command+7 (on keyboard)
*)
tell application "Pro Tools" to activate
tell application "System Events"
    key code 26 using command down -- 0x1a (26) =>  7 on (English) keyboard, not on keypad
end tell


Regards,

H

Emulating pressing F6 & F7 together with Applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.